How do I postback whenever a user types in a textbox to filter results in a div tag.
+1
A:
There are a couple of neat jQuery plugins that do exactly this. My favorite is jQuery LiveSearch but if you google jQuery AJAX search you'll find a bunch out there.
Chris Pebble
2009-01-28 14:42:39
A:
<script language=javascript>
$(document).ready(function() {
$("#SearchBox").focus();
$("#SearchBox").keyup(function(event) {
var e = window.event || e
var keyunicode = e.charCode || e.keyCode
//Allow alphabetical keys, plus BACKSPACE and SPACE
if (keyunicode >= 65 && keyunicode <= 122 || keyunicode == 8 || keyunicode == 32) {
$("#SubBut").click();
}
});
});
function SetEnd(TB) {
var FieldRange = TB.createTextRange();
FieldRange.moveStart('character', TB.value.length);
FieldRange.select();
}
</script>
Add onfocus="SetEnd(this) to the properties of your search input control. This will set the caret to the end of the text.
This will only postback when an alphanumeric character is entered into the textbox, including delete.
Hope this helps someone.
Note I have only tested this on IE7 therefore some things may not work in Firefox or other browsers.
dean nolan
2009-01-30 11:59:01
the problem is you don't want to post back, which will refresh your page, you just want to send a POST request via AJAX.
Nick Berardi
2009-01-30 12:01:23
Yeah I know but the code in place above is still needed as the procedure to call the ajax.
dean nolan
2009-02-02 11:07:39