gotornot Posted June 26, 2012 Share Posted June 26, 2012 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 More sharing options...
dc2007 Posted June 26, 2012 Share Posted June 26, 2012 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 More sharing options...
gotornot Posted June 26, 2012 Author Share Posted June 26, 2012 That doesnt appear to work all i just changed was the script at the top? Link to comment https://forums.phpfreaks.com/topic/264835-php-jquery/#findComment-1357241 Share on other sites More sharing options...
dc2007 Posted June 26, 2012 Share Posted June 26, 2012 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.