Stop Enter key (default submit method) & replace with specified method

/ Published in: jQuery
Save to your folder(s)

13 is Enter key
return false cancels the postback
<p>In this case I am calling the javascript <strong>doPostBack and telling it to execute the txtBox<em>TextChanged method
brief tutorial on _</em>doPostBack here: <a href=""><em>Understanding_the_JavaScript___doPostBack_Function.all</a></p>

Copy this code and paste it in your HTML
  1. //prevent page submit on enter key press
  2. //call the postback javascript then cancel the enter key press
  3. $(document).keydown(function (e) {
  4. if (e.keyCode == 13) {
  5. __doPostBack('txtBox_TextChanged', '');
  6. return false;
  7. }
  8. });

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.