|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Enter key problemOn my page, there are several textboxes, a Save button and a Cancel Button.
When u press enter key in any of the textboxes, it does the same thing as u click on the Save button. Which is not I wanted. I wish pressing Enter do nothing. Anyone can help me to solve this problem? Peter Peter-
Usability aside (people expect that Enter does something, so disabling it can confuse some), JavaScript can catch and then disregard the Enter key. <head runat="server"> <script type="text/javascript"> function catchEnterKey() { if (window.event.keyCode == 13) { event.returnValue=false; event.cancel = true; } } </script> </head> Then, on your body tag: <body onkeydown="catchEnterKey()"> Another way to do this would be to have a specified button you want to execute and use the form's defaultbutton attribute to set it to that form. If you have required fields, use validators to ensure they are filled in, etc. prior to submission. HTH. -dl Show quote > On my page, there are several textboxes, a Save button and a Cancel > Button. When u press enter key in any of the textboxes, it does the > same thing as u click on the Save button. Which is not I wanted. I > wish pressing Enter do nothing. > > Anyone can help me to solve this problem? > > Peter > |
|||||||||||||||||||||||