Chris P
10-28-2005, 02:04 PM
Hello
I am trying to learn/write a function that will automatically get the form membership of an element and print out the index of that element. From here (http://www.mattkruse.com/javascript/tabnext/source.html) I have this code:
function getElementIndex(obj) {
var theform = obj.form;
document.getElementById("elementIndex").value=obj.form; //show form
for (var i=0; i<theform.elements.length; i++) {
if (obj.id == theform.elements[i].id) {
return i;
}
}
return -1;
}
My problem is that If I pass this an element the code never captures the form. That diagnostic show form line just prints [object HTMLForm] and not the form of the element. What is the correct syntax to pass a function a form element and have the function extract the form and use it in the script? tia.
I am trying to learn/write a function that will automatically get the form membership of an element and print out the index of that element. From here (http://www.mattkruse.com/javascript/tabnext/source.html) I have this code:
function getElementIndex(obj) {
var theform = obj.form;
document.getElementById("elementIndex").value=obj.form; //show form
for (var i=0; i<theform.elements.length; i++) {
if (obj.id == theform.elements[i].id) {
return i;
}
}
return -1;
}
My problem is that If I pass this an element the code never captures the form. That diagnostic show form line just prints [object HTMLForm] and not the form of the element. What is the correct syntax to pass a function a form element and have the function extract the form and use it in the script? tia.