I have a list of input fields and when I tab through them I want to loop back to the first one, but it doesn’t seem to work.
Here is my HTML
<form id="form">
<input id="mon" type="text"/> Month<br>
<input id="day" type="text"/> Day<br>
<input id="num" type="text"/> Year<br>
<input id="amt" type="text"/> Amount<br>
</form>
and my javascript
window.onload=function(){
$('mon').focus();
$('amt').onblur=function(){
//Process the input fields
$('mon').focus();
}
}
function $(a){return document.getElementById(a)}
I think your
onblurevent handler is being called before the default handler, causing focus to shift first to input ‘mon’, then to whatever the browser thinks should be in focus next. Try using theonkeypressevent. e.g.Edit:
onkeydownactually seems to work in more browsersEdit 2: added IE case. IE doesn’t always pass the event as an argument