i am trying to similate an "ENTER" as a key to switch focus in a
sequence of text inputs. i don't want to use "event.keyC ode" since i
want to do additional testing before i decide which text input i want
to focus next. the following are the test code i have, whenever i hit
"enter", it will act clicking the submit button. what can i do to
avoid this problem?
<!-- ############# code begins here ############ -->
<html>
<head>
<script language="JavaS cript">
function jsKeyForeward(t hisID)
{
var thatID = "t0";
if (thisID == "t0")
thatID = "t1";
if (thisID == "t1")
thatID = "t2";
if (thisID == "t2")
thatID = "t0";
document.forms[0].elements[thatID].focus();
}
function jsKeyBackward(t hisID)
{
var thatID = "t0";
if (thisID == "t0")
thatID = "t2";
if (thisID == "t1")
thatID = "t0";
if (thisID == "t2")
thatID = "t1";
document.forms[0].elements[thatID].focus();
}
function jsKeyEvent(this ID)
{
if (event.keyCode == 13 || event.keyCode == 40)
{
if (event.keyCode == 13)
event.keyCode = 40;
jsKeyForeward(t hisID);
}
else
{
if (event.keyCode == 38)
{
jsKeyBackward(t hisID);
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="submit" name="b0" value="submit" id="b0" /><br>
<input name="t0" type="text" id="t0"
onKeyDown="java script:jsKeyEve nt(this.id);" /><br>
<input name="t1" type="text" id="t1"
onKeyDown="java script:jsKeyEve nt(this.id);" /><br>
<input name="t2" type="text" id="t2"
onKeyDown="java script:jsKeyEve nt(this.id);" /><br>
</form>
</body>
</html>
<!-- ############# code ends here ############ -->
sequence of text inputs. i don't want to use "event.keyC ode" since i
want to do additional testing before i decide which text input i want
to focus next. the following are the test code i have, whenever i hit
"enter", it will act clicking the submit button. what can i do to
avoid this problem?
<!-- ############# code begins here ############ -->
<html>
<head>
<script language="JavaS cript">
function jsKeyForeward(t hisID)
{
var thatID = "t0";
if (thisID == "t0")
thatID = "t1";
if (thisID == "t1")
thatID = "t2";
if (thisID == "t2")
thatID = "t0";
document.forms[0].elements[thatID].focus();
}
function jsKeyBackward(t hisID)
{
var thatID = "t0";
if (thisID == "t0")
thatID = "t2";
if (thisID == "t1")
thatID = "t0";
if (thisID == "t2")
thatID = "t1";
document.forms[0].elements[thatID].focus();
}
function jsKeyEvent(this ID)
{
if (event.keyCode == 13 || event.keyCode == 40)
{
if (event.keyCode == 13)
event.keyCode = 40;
jsKeyForeward(t hisID);
}
else
{
if (event.keyCode == 38)
{
jsKeyBackward(t hisID);
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="submit" name="b0" value="submit" id="b0" /><br>
<input name="t0" type="text" id="t0"
onKeyDown="java script:jsKeyEve nt(this.id);" /><br>
<input name="t1" type="text" id="t1"
onKeyDown="java script:jsKeyEve nt(this.id);" /><br>
<input name="t2" type="text" id="t2"
onKeyDown="java script:jsKeyEve nt(this.id);" /><br>
</form>
</body>
</html>
<!-- ############# code ends here ############ -->
Comment