allida77
08-27-2004, 09:26 PM
I know this has been before but I needed an autotab method that could move to the next field without knowing what ID or type to look at. I have some forms (surveys) that are built on the fly and I have no of field IDs or types. This method allows you to pass in the field object and then look through its siblings to find the next form field to focus.
function inputAutoTab(node){
var siblingNode=node.nextSibling;
var isFound = false;
if(node.nodeName.toLowerCase()=="input"&&node.value.length==node.getAttribute("maxlength")){
while(!isFound&&siblingNode.nextSibling)
{
if((siblingNode.nodeName.toLowerCase()=="input")||(siblingNode.nodeName.toLowerCase()=="select")||(siblingNode.nodeName.toLowerCase()=="textarea")){
siblingNode.focus();
isFound=true;
}
siblingNode=siblingNode.nextSibling
}
}
}
The sample was just done on the fly. After doing it though I realized that autotabbing is nice when it is going to a textbox but when it goes to a check box it kind of stinks because you have to go back to your mouse.:mad: A user also might not know where the focus is. So I think I will add a bold border or bg and as the user tabs through set the bg or border to a lighter shade. Any other improvements or suggestions are welcomed.
function inputAutoTab(node){
var siblingNode=node.nextSibling;
var isFound = false;
if(node.nodeName.toLowerCase()=="input"&&node.value.length==node.getAttribute("maxlength")){
while(!isFound&&siblingNode.nextSibling)
{
if((siblingNode.nodeName.toLowerCase()=="input")||(siblingNode.nodeName.toLowerCase()=="select")||(siblingNode.nodeName.toLowerCase()=="textarea")){
siblingNode.focus();
isFound=true;
}
siblingNode=siblingNode.nextSibling
}
}
}
The sample was just done on the fly. After doing it though I realized that autotabbing is nice when it is going to a textbox but when it goes to a check box it kind of stinks because you have to go back to your mouse.:mad: A user also might not know where the focus is. So I think I will add a bold border or bg and as the user tabs through set the bg or border to a lighter shade. Any other improvements or suggestions are welcomed.