I have a form where the name of each input is part of a php array, with the first piece of code below for the input. What I’m trying to do is switch the cursor to the next input box after the user inputs the max size for the input. I’m having a problem with passing the name of the next input to the javascript function.
[CODE]for($count = 0; $count < 18; $count++) {
$next = $count+1;
echo “<td><input type=”text” size=”2″ name=”putts[$count]” onkeyup=”TabNext(this,’up’,1,this.form.putts[$next])” onkeydown=”TabNext(this,’down’,1)” maxlength=”1″ value=””.$card[“putts”][$count].””/></td>”;
}
Here is the javascript. I’m having problems with the next_field.focus() to go to the next input.
[CODE]var phone_field_length=0;
function TabNext(obj,event,len,next_field) {
if (event == “down”) {
phone_field_length=obj.value.length;
}
else if (event == “up”) {
if (obj.value.length != phone_field_length) {
phone_field_length=obj.value.length;
if (phone_field_length == len) {
next_field.focus();
}
}
}
}
obj : The input object (this)
event: Either ‘up’ or ‘down’ depending on the keypress event
len : Max length of field – tab when input reaches this length
next_field: input object to get focus after this one
Any help would be appreciated.
Thanks.