Posted By

shibbard on 05/11/10


Tagged


Versions (?)

ASP.Net Trigger button with Enter


 / Published in: JavaScript
 

URL: http://stackoverflow.com/questions/494076/jquery-and-asp-net-forcing-button-click

  1. $('#textBoxId').keydown(function(e) {
  2. if(e.keyCode === 13) {
  3. e.preventDefault();
  4. $('#buttonId').trigger('click');
  5. }
  6. });
  7.  
  8. or - not tested:
  9.  
  10. $('#textBoxId').keydown(function(event) {
  11. var e = event || window.event;
  12. var keyCode = document.all ? e.keyCode : e.which;
  13.  
  14. if (keyCode == 13) {
  15. e.preventDefault();
  16. $('#buttonId')[0].click();
  17. }
  18. });

Report this snippet  

You need to login to post a comment.