J
jerrygarciuh
Hello,
I have been playing with various Googled solutions for capturing the <Enter>
key to suppress form submission.
My first question is whether anyone has a script that works in all common
browsers? The script bellow is IE only. It fails FF 1.0 and NN 7.
Also, if I can trap the keypress I would like to use it to tab to the next
tabindex.
Is that possible? Ca I grab current focused tabindex?
TIA,
jg
__CODE__
<script language=javascript>
<!--
var bIsEnterKey = false;
function checkKeyPress(){
return !bIsEnterKey;
}
function setKeyPress(){
if(event && event.which){ //if which property of event object is
supported (NN4)
characterCode = event.which //character code is contained in NN4's which
property
}
else{
characterCode = event.keyCode;//character code is contained in IE's
keyCode property
}
bIsEnterKey = (characterCode.toString() == '13');
window.setTimeout("bIsEnterKey=false;",1000);
}
//-->
</script>
<form name="form1" method="post" action="xxx.html" onsubmit="return
checkKeyPress();" onkeypress="setKeyPress()">
<input type="text" name="textfield">
</form>
I have been playing with various Googled solutions for capturing the <Enter>
key to suppress form submission.
My first question is whether anyone has a script that works in all common
browsers? The script bellow is IE only. It fails FF 1.0 and NN 7.
Also, if I can trap the keypress I would like to use it to tab to the next
tabindex.
Is that possible? Ca I grab current focused tabindex?
TIA,
jg
__CODE__
<script language=javascript>
<!--
var bIsEnterKey = false;
function checkKeyPress(){
return !bIsEnterKey;
}
function setKeyPress(){
if(event && event.which){ //if which property of event object is
supported (NN4)
characterCode = event.which //character code is contained in NN4's which
property
}
else{
characterCode = event.keyCode;//character code is contained in IE's
keyCode property
}
bIsEnterKey = (characterCode.toString() == '13');
window.setTimeout("bIsEnterKey=false;",1000);
}
//-->
</script>
<form name="form1" method="post" action="xxx.html" onsubmit="return
checkKeyPress();" onkeypress="setKeyPress()">
<input type="text" name="textfield">
</form>