PHP & JQUERY

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
gotornot
Forum Commoner
Posts: 54
Joined: Fri Jul 31, 2009 2:30 am

PHP & JQUERY

Post 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?
Last edited by Christopher on Tue Jun 26, 2012 7:30 pm, edited 2 times in total.
Reason: Moved to Javascript forum by moderator.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP & JQUERY

Post by pickle »

$("#form") won't match anything. "#" matches an "id" attribute, and you've only given your form a "name" attribute.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply