I have a form on one of my pages and I am trying to make an auto-tab function where it checks when you get to the end of a field it automatically tabs to the next and so far so good but what I want to do is to get the array index for a given element which I supply the name for instance

document.forms[0].elements["dd"];

Where dd is a field in my form, how can I get the number of the element or
document.forms[0].elements[6];
automatically can I convert it somehow.