jquery - Trigger function on Enter keypress -
i've simple search function want trigger on enter key press, though function executes form posted.
<script> function search() { ... } $(document).ready(function() { $("#text").keypress(function (e) { if (e.which==13) search(); }); }); <body> <form id="searchform" name="searchform"> <input size="40" id="text" type="text" name="text" class="input" /> </form> </body>
bind function submit event , prevent default:
$('form').submit(function(ev){ ev.preventdefault(); /* code here */ });
Comments
Post a Comment