Michael Price wrote:
I've got five text boxes representing the four (or five for longer ones)
parts of a credit card number. They all follow one another in the DOM
without any other elements in between.
What I want to do is when 4 digits have been typed into one box,
auto-focus the next one. I could do this:
$("#box1").keyup(function() {
// IF LENGTH IS 4 FOCUS BOX2
});
$("#box2").keyup(function() {
// IF LENGTH IS 4 FOCUS BOX3
});
$("#box3").keyup(function() {
// IF LENGTH IS 4 FOCUS BOX4
});
$("#box4").keyup(function() {
// IF LENGTH IS 4 FOCUS BOX5
});
Typical, two minutes after posting I come up with this:
$("#CN1, #CN2, #CN3, #CN4, #CN5").keyup(function() {
if ($(this).val().length == 4) {
$(this).next("input,select").focus();
}
});
Anyone got any advance on this?
Regards,
Michael Price