Hi,
I'm trying to determine a better method of finding the index value of a form element. I need to find it because the JavaScript validation class has a function for validating a single form element, but it requires that the index number of the element in the form be passed in.
Currently I am accomplishing this by a function that I wrote which I call for each field I want to validate:
function getIndex(element)
{
for (var i=0; i<document.thisForm.elements.length; i++)
if (element == document.thisForm.elements[i])
return i;
return -1;
}
This works fine, however the other developer working on this and I don't really feel good about having to run this loop every for every field we want to validate.
I have looked into other methods of finding the index and I ran into the sourceIndex variable:
var ivIndex = document.thisForm.elements("foo").sourceIndex;
Now, this seems to do something however I am not sure whether it does what I actually want it to do. For example, when I run this against a field that I know should have a form index value of 7, I am getting 161... And when I run it against a field with an index of 10, I get 169. Not very intuitive as to what it is doing.
Anyway, if anyone knows any wizard hax tricks to getting the index of a field within the form element, let me know it would be greatly appreciated. :)