469,947 Members | 2,176 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,947 developers. It's quick & easy.

Get ordinal of form element

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+.

Jul 23 '05 #1
2 1541


st********@yahoo.com wrote:
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[i]) {
alert('index is ' + i);
break;
}
}
}

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
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

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by CJ | last post: by
5 posts views Thread by Richard Cornford | last post: by
4 posts views Thread by Stuart Perryman | last post: by
4 posts views Thread by Mark Tarver | last post: by
7 posts views Thread by Dylan Parry | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.