Avoi enter key in IE and Netscape

R

Robert Scheer

Hi.

I wrote this function to avoid the enter key in some of my textboxes.
In IE the function works as expected, in Netscape 6 or 7 it does not
work. How can I make my function works in both IE and Netscape.

<input type="text" maxlength="13" id="txtType" onKeyPress="NoEnter();"
/>

<Script language='Javascript'>
function NoEnter()
{
if (window.event.keyCode == 13)
{
window.event.cancelBubble = true;
window.event.returnValue = false;
}
}
</Script>

Thanks,

Robert Scheer
 
R

Robert Scheer

Hi Lasse,

thanks for the detailed information. It was very useful!

I tried the first suggestion you gave me, and changed my function this way:

<script type='text/javascript'>
function NoEnter(event) {
event = event || window.event;
if (event.keyCode == 13) {
if (event.preventDefault) {
event.preventDefault();
} else {
event.returnValue = false;
}
}
}
</script>

I tried the modified code on IE 6 and it worked. Then I tried on Netscape 6
and 7, and it didn't work. I am calling the function as before:
<input type="text" maxlength="13" id="txtType" onKeyPress="NoEnter();" />

Can you help me one more time?

Thanks,

Robert Scheer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top