SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Jan 5, 2001, 16:40 #1
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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.Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Jan 6, 2001, 06:37 #2
- Join Date
- Jul 2000
- Location
- Warwickshire, England
- Posts
- 557
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Would document.forms[0].elements[0].name be what you are looking for? or are you looking to convert the name into index?
-
Jan 6, 2001, 06:59 #3
- Join Date
- Jul 2000
- Location
- Warwickshire, England
- Posts
- 557
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
aha.. I think you will have to use the name property and something like..
function getIndex(what,which)
{
for (var i=0;i < what.elements.length;i++)
{
if (what.elements[ i ].name == which) {return i;}
}
return -1;
}
alert( getIndex(document.forms[0], "dd") );
-
Jan 6, 2001, 11:26 #4
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Why yes thanks
Please don't PM me with questions.
Use the forums, that is what they are here for.
Bookmarks