Jump to content

PHP & JQUERY


gotornot

Recommended Posts

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:

 

<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:

 

<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?

Link to comment
https://forums.phpfreaks.com/topic/264835-php-jquery/
Share on other sites

try this mate

 

<script type="text/javascript">


    function get() {
        $.post('search_tsr.php', { search_term: $("#Name").val() },
            function(output) {
                $('#search_results').html(output).show();
            });
    }
$("#SceneName").live("keypress", function(e) {
        if (event.keyCode == 13) {
         $("#form").submit();
        $.post('search_tsr.php', { search_term: form.name.value },
            function(output) {
                $('#search_results').html(output).show();
            });
         
        }
    });

</script>


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

Link to comment
https://forums.phpfreaks.com/topic/264835-php-jquery/#findComment-1357235
Share on other sites

try this mate

 

<script type="text/javascript">
    function get() {
        $.post('search_tsr.php', { search_term: $("#Name").val() },
            function(output) {
                $('#search_results').html(output).show();
            });
    }
$("#SceneName").live("keypress", function(e) {
         $("#form").submit();
        $.post('search_tsr.php', { search_term: $("#Name").val() },
            function(output) {
                $('#search_results').html(output).show();
            });
    });

</script>


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

<div id="search_results"></div>

Link to comment
https://forums.phpfreaks.com/topic/264835-php-jquery/#findComment-1357254
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.