Can someone fix the right and left here?
Up and down does the trick, navigating inside the textboxes seem to take precedense
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>test tab</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js"></script>
<script type="text/javascript">
function checkKey(e){
switch (e.keyCode) {
case 40:
current = $("#field1");
$("#msg").html(current.id);
setTimeout('focusIt()',100);
break;
case 38:
current = $("#field3"); // or some more clever way of finding the last field
$("#msg").html(current.id);
setTimeout('focusIt()',100);
break;
case 37:
if (prev) current = prev;
else current = $("#field3"); // or some more clever way of finding the last field
$("#msg").html(current.id);
setTimeout('focusIt()',100);
break;
case 39:
if (next) current = next;
else current = $("#field1")
$("#msg").html(current.id);
setTimeout('focusIt()',100);
break;
default:
}
}
function focusIt() {
if(current) {current.focus(); current.select() }
}
var current,next,prev;
$(document).ready(function() {
if ($.browser.mozilla) {
$("input").keypress (checkKey);
} else {
$("input").keydown (checkKey);
}
$("input").focus(function() {
current=this;
$("#msg").html(current.id);
next = $("field"+(parseInt(current.id.replace('field',''))+1));
prev = $("field"+(parseInt(current.id.replace('field',''))-1));
});
});
</script>
</head>
<body>
<div id="pagecontent" style="width:95%; margin:10px 10px 10px 10px">
<form>
<input type="text" id="field1" value="first"/><input type="text" id="field2" value="second"/><input type="text" id="field3" value="third"/>
</form>
<span id="msg"></span>
</div>
</body>
</html>