P
P E Schoen
I noticed that in IE9 if I entered data in a text box in a form and hit the
<Enter> key, it would cause an error sound and not act as I expected, like
the <Tab> key, to advance to the next control and activate the onChange
event to update other controls. It worked OK in Firefox but not IE9. Grrr!
So I found some references:
http://webcheatsheet.com/javascript/disable_enter_key.php
http://www.cs.tut.fi/~jkorpela/forms/enter.html
The second reference used a rather convoluted way to achieve the desired
effect. But the first reference gave me an idea:
<script type="text/javascript">
function stopRKey(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"))
{
// window.postMessage(String.fromCharCode(9), window.location);
node.blur();
return false;}
}
document.onkeypress = stopRKey;
</script>
I tried to simulate the sending of the <Tab> character to replace the <CR>
character, but that didn't work. However, the blur() works well enough
except it removes focus and you have to click on the next control.
I have implemented this here:
http://www.enginuitysystems.com/EVCalculator.htm
Any ideas on a better way to do this?
Thanks.
Paul
<Enter> key, it would cause an error sound and not act as I expected, like
the <Tab> key, to advance to the next control and activate the onChange
event to update other controls. It worked OK in Firefox but not IE9. Grrr!
So I found some references:
http://webcheatsheet.com/javascript/disable_enter_key.php
http://www.cs.tut.fi/~jkorpela/forms/enter.html
The second reference used a rather convoluted way to achieve the desired
effect. But the first reference gave me an idea:
<script type="text/javascript">
function stopRKey(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"))
{
// window.postMessage(String.fromCharCode(9), window.location);
node.blur();
return false;}
}
document.onkeypress = stopRKey;
</script>
I tried to simulate the sending of the <Tab> character to replace the <CR>
character, but that didn't work. However, the blur() works well enough
except it removes focus and you have to click on the next control.
I have implemented this here:
http://www.enginuitysystems.com/EVCalculator.htm
Any ideas on a better way to do this?
Thanks.
Paul