Web Forms and the Enter Key
-
Hi folks, help you can help me. I have a base web page that all my forms are inheriting from and i want to use it to control the behaviour of the enter key in the inheriting pages. Specifically, i need to ignore the enter key if it is pressed on any type of control other than a button control, either a html or asp button. I was thinking of JScript but don't know how to determine wether the object that had focus when the enter key was pressed was a button or not. Anyone able to help with this? Cheers Kev
-
Hi folks, help you can help me. I have a base web page that all my forms are inheriting from and i want to use it to control the behaviour of the enter key in the inheriting pages. Specifically, i need to ignore the enter key if it is pressed on any type of control other than a button control, either a html or asp button. I was thinking of JScript but don't know how to determine wether the object that had focus when the enter key was pressed was a button or not. Anyone able to help with this? Cheers Kev
Check this javascript works well for me
function clickButton() { if (event.keyCode == 13) { if ( document.Form1.all.BT_Name != null) document.Form1.all.BT_Name.click(); return false; } }
Cheers Al -
Check this javascript works well for me
function clickButton() { if (event.keyCode == 13) { if ( document.Form1.all.BT_Name != null) document.Form1.all.BT_Name.click(); return false; } }
Cheers AlI was after soemthing more generic that would work at a page level for all objects on the page, any button that has focus when enter is pressed will fire, any other control will not cause the page to be submited. One of the guys at work sent me this from a google group.
function disableEnter(evt) { var evt = (evt) ? evt : ((event) ? event : null); var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if ((evt.keyCode == 13) && (node.type=="text")) { return false; } } document.onkeypress = disableEnter;
It seems to work for what i want, maybe it will help anyone else who needs to do this sort of thing. Cheers Kev