Page 1 of 1

PHP & JQUERY

Posted: Tue Jun 26, 2012 4:42 pm
by gotornot
Hi

i am trying to get a search box to work on both click a button or an enter action yet i cant get the enter action to work as well as enter.
I know this isnt strictly php but i am using all php functions with the search and wondered if anyone could help.

This is my code:

Code: Select all

<script type="text/javascript">

    function get() {
        $.post('search_tsr.php', { search_term: form.name.value },
            function(output) {
                $('#search_results').html(output).show();
            });
    }
$(document).ready(function() {
    $(document).keyup(function(event) {
        if (event.keyCode == 13) {
         $("#form").submit();
        $.post('search_tsr.php', { search_term: form.name.value },
            function(output) {
                $('#search_results').html(output).show();
            });
         
        }
    })
});

</script>
The form is below:

Code: Select all

<form name="form">
                  <img src="gfx/search_magnifyer.jpg" width="18" height="18" border="0" align="absmiddle">   
                  <input name="name" type="text"><input type="button" onClick="get()" value="Go">
</form>
Anyone can you help?

Re: PHP & JQUERY

Posted: Fri Jul 06, 2012 11:17 am
by pickle
$("#form") won't match anything. "#" matches an "id" attribute, and you've only given your form a "name" attribute.