Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Get ordinal of form element

Reply
Thread Tools

Get ordinal of form element

 
 
stewartfip@yahoo.com
Guest
Posts: n/a
 
      06-01-2005
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+.

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      06-01-2005


http://www.velocityreviews.com/forums/(E-Mail Removed) 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/
 
Reply With Quote
 
 
 
 
stewartfip@yahoo.com
Guest
Posts: n/a
 
      06-01-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to get a column by name instead of ordinal? needin4mation@gmail.com ASP .Net 4 08-02-2005 08:36 PM
moving from form element to form element Rod Snyder ASP .Net 1 05-29-2004 01:55 PM
get the form element from a frame element Mr. x HTML 3 12-11-2003 08:44 PM
Determing the ordinal position of items in ListBox SamIAm ASP .Net 1 09-29-2003 07:16 AM
Re: Ordinal Expression from String Ion Chalmers Freeman Java 0 07-27-2003 07:40 PM



Advertisments