Get ordinal of form element

Discussion in 'Javascript' started by stewartfip@yahoo.com, Jun 1, 2005.

  1. Guest

    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+.
     
    , Jun 1, 2005
    #1
    1. Advertising

  2. 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) {
    alert('index is ' + i);
    break;
    }
    }
    }

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 1, 2005
    #2
    1. Advertising

  3. Guest

    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
     
    , Jun 1, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SamIAm
    Replies:
    1
    Views:
    1,524
    Andrew de la Harpe
    Sep 29, 2003
  2. Replies:
    4
    Views:
    2,190
  3. Ion Chalmers Freeman

    Re: Ordinal Expression from String

    Ion Chalmers Freeman, Jul 27, 2003, in forum: Java
    Replies:
    0
    Views:
    703
    Ion Chalmers Freeman
    Jul 27, 2003
  4. Chris Smith
    Replies:
    1
    Views:
    822
    Adam Maass
    May 16, 2005
  5. diegomrosa
    Replies:
    6
    Views:
    43,453
    Roedy Green
    Nov 19, 2005
Loading...

Share This Page