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.
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.