Broken Event Model in IE

G

getsanjay.sharma

Any reason why the following snippet works as expected in Firefox but
fails miserably in IE?

<html>
<head>
<script>
var ENTER_KEY = 13;

function myKeyPressed(e)
{
if(!e)
var e = window.event;
if(e.keycode)
code = e.keycode;
else if(e.which)
code = e.which;

if(code == ENTER_KEY)
{
alert('You pressed the ENTER key');
return true;
//call the function which performs calculation
}
else
{
alert('Press the correct key');
return false;
}
}
</script>
</head>
<body>
<form>
<label>Box</label><input type="text" name="txt" id="txt"
onkeypress="javascript:return myKeyPressed(event)" />
</form>
</body>
</html>

Some good links referring to the events in JS would be appreciated.

Thanks and regards,
S T S.
 
G

Geoffrey Summerhayes

Any reason why the following snippet works as expected in Firefox but
fails miserably in IE?

<html>
<head>
<script>
var ENTER_KEY = 13;

function myKeyPressed(e)
{
if(!e)
var e = window.event;
if(e.keycode)
code = e.keycode;
else if(e.which)
code = e.which;

javaScript camelCase

e.keyCode
Some good links referring to the events in JS would be appreciated.

Don't really have any. I usually bounce between mozilla's
developer ref, W3, and MSDN.

Strangely, I find the MS ref. the easiest to find things in.
 
G

getsanjay.sharma

javaScript camelCase

e.keyCode


Don't really have any. I usually bounce between mozilla's
developer ref, W3, and MSDN.

Thanks a lot Geoff. I thought that since onclick was the same as
onClick, the same can be applied anywhere, but I guess it was a wrong
thought. Maybe a search for 'Mozilla Javascript reference', 'W3C
Javascript reference' or 'MSDN javascript reference' should turn out
to be fruitful.

Thanks and Regards,
S T S.
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top