I just tried this (for fun). Works in IE version 6.0.2800.1106, but does
nothing in Netscape 7.0.
I take it that the syntax for Netscape is completely different?
Shane
-----Original Message-----
From: Robert Nyman [mailto:robert.nyman@c...]
Sent: Wednesday, October 30, 2002 8:49 AM
To: JavaScript HowTo
Subject: [javascript_howto] SV: Re: SV: Return Key/Enter Key Event Handler
part II
Hi,
First of all, I have to apologize to Kriz and you, Claudio.
There was a small syntax error in my code, as well as putting the
returnValue at the wrong place.
But the code below has been tested by me, and it works like a charm!
:-D
<html>
<head>
<title>Test for lists</title>
<script language="Javascript">
function EnterHandler(oElm) {
if(event.keyCode == 13){
var intNewIndexFocus
parseInt(oElm.getAttribute("indexNo"), 10) + 1;
var arrInputFields
document.getElementById("myform").getElementsByTagName("input");
for(var i=0; i<arrInputFields.length; i++){
var oInput = arrInputFields[i];
if(oInput.getAttribute("type") == "text" &&
parseInt(oInput.getAttribute("indexNo"), 10) == intNewIndexFocus){
oInput.focus();
}
}
event.returnValue = false;
}
}
</script>
</head>
<body>
<form name="myform">
<font size="2">SurName</font><br>
<input name="surname" type="text" indexNo="1"
onKeyDown="EnterHandler(this)"><br>
<font size="2">FirstName</font><br>
<input name="firstname" type="text" indexNo="2"
onKeyDown="EnterHandler(this)"><br>
<font size="2">FirstName</font><br>
<input name="firstname" type="text" indexNo="3"
onKeyDown="EnterHandler(this)"><br>
<font size="2">FirstName</font><br>
<input name="firstname" type="text" indexNo="4"
onKeyDown="EnterHandler(this)"><br>
<font size="2">FirstName</font><br>
<input name="firstname" type="text" indexNo="5"
onKeyDown="EnterHandler(this)"><br>
</form>
</body>
</html>
/Robert