Posted By

ecavazos on 01/18/08


Tagged

key enter aspnet keypress


Versions (?)

Capturing The Enter Key Keypress in ASP.NET


 / Published in: JavaScript
 

This is to prevent a form from being inadvertently submitted.

  1. <script type="text/javascript">
  2. ////////////////////////////////
  3. // prototype.js is required
  4. ////////////////////////////////
  5.  
  6. var tbox = '<%= txtSearch.ClientID %>';
  7. var sbtn = '<%= btnSearch.ClientID %>';
  8.  
  9. Event.observe(window, 'load', init, false);
  10.  
  11. function init(){
  12. Event.observe(tbox, "keypress", function(e){checkEnter(e)});
  13. }
  14.  
  15. function checkEnter(e){
  16. if (e.keyCode == 13){
  17. $(sbtn).click();
  18. Event.stop(e);
  19. }
  20. }
  21. </script>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: nileshkale on February 14, 2008

it good for programmer

You need to login to post a comment.