tags:

views:

1155

answers:

3

How do I postback whenever a user types in a textbox to filter results in a div tag.

+3  A: 

I think this is an interesting article for you:

jQuery Live Ajax Search Plug-in

Natrium
+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
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
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
Yeah I know but the code in place above is still needed as the procedure to call the ajax.
dean nolan