Get ordinal of form element

S

stewartfip

How do I get the ordinal of a form element from a reference to the
object itself.

For example:

<html>
<script language="javascript">
function disp_val(objField){
alert(---the ordinal of objField in form---)
}
</script>
<body>
<form>
<input type="text" onblur="disp_val(this)"><br>
<input type="text" onblur="disp_val(this)">
</form>
</body>
</html>

I need to pass the ordinal to another function which I have no control
over. Not having any luck figuring this out. I'm sure it's simple and
I'm missing the obvious solution. I'm workign strictly with IE 5.5+.
 
M

Martin Honnen

How do I get the ordinal of a form element from a reference to the
object itself.

For example:

<html>
<script language="javascript">
function disp_val(objField){
alert(---the ordinal of objField in form---)

You need a loop:

var form;
if ((form = objField.form)) {
for (var i = 0; i < form.elements.length; i++) {
if (objField == form.elements) {
alert('index is ' + i);
break;
}
}
}
 
S

stewartfip

Thanks, Martin!

That's the situation I was trying to avoild, but it was the only
conclusion I could draw myself. That's the way I have to go, I guess!

Thanks again!
Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top