javascript - Enter key does not work in search box -
tried search guys sorry. input in search box doesnt work (or search) when hit enter when user clicks search button. doing wrong? here code. thanks.
<script type="text/javascript"> $(document).ready(function() { $("#submit").click(function() { var url = "http://asla.org/awardssearch.html"; url += "?s=" + $('#googlecse').val(); window.location = url; }); $('#googlecse').keydown(function(event) { if (event.keycode == '13') { $("#submit").click(); } else { //do nothing :) } }); }); </script> <form class="navbar-form navbar-right" role="search"> <div class="search"> <input id="googlecse" type="text" onblur="if(this.value=='')this.value=this.defaultvalue;" onfocus="if(this.value==this.defaultvalue)this.value='';" value="search awards" name="search awards" /> <input id="submit" type="button" value="search" /> </div> </form>
if changed #submit
element's type
"submit", wouldn't need manually handle anyway default browser behaviour:
<input id="submit" type="submit" value="search" />
now rather handling #submit
button's click event, can instead handle form
element's submit
event:
$('form[role="search"]').submit(function() { var url = "http://asla.org/awardssearch.html"; url += "?s=" + $('#googlecse').val(); window.location = url; });
Comments
Post a Comment