ASP.Net Trigger button with Enter


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



Copy this code and paste it in your HTML
  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. });

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.