What is cursor key? I don’t have a key called that on my keyboard?
I can’t tell what your script wants to do. Who is document.getElementById(nextfield) ? some other element with the id of “b0”?
You are also returning false. Is this to catch people using ENTER to submit the form without putting in any input? Yeah, I think browsers should force users to navigate focus to the submit button first, but it’s too late: people are used to hitting enter, except when focussed on a textarea.
If you are trying to make sure something’s typed in, you could try something different (without regard to which key is used… because this is not the same per keyboard. You can maybe get away with US keyboards all having the same keycode, but beyond those… most of the command buttons can be different. For example the : key may be different between browsers).
Read more about keycode and charcode trouble: http://www.quirksmode.org/js/keys.html
First, you could say
onblur(this), if this.value == “”
this.focus or whatever.focus
Though this should sufficiently annoy users : ) But if, when they leave the input, if it’s empty, move the focus back to the same input (you could also try a return false in there too to stop submission).
You could also try onchange or onkeyup, but this may hurt users who are backspacing a field empty so they can change their answer.
Or you could just check all your inputs when the user tries to submit.
document.forms[‘thisformID’].submit() {
//check the inputs
//if their values == “”
//return false
//otherwise
//return true (let the form submit)
}
This would be faster if you have a lot of inputs, but it doesn’t tell the user right away that something needs to be filled in.
Best thing to do in all cases is explain (before/above the form) that inputs must be filled in first. Then use Javascript to catch them if they miss (esp if they are hitting ENTER by accident).