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

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

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

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,689
    Andrew de la Harpe
    Sep 29, 2003
  2. Rod  Snyder

    moving from form element to form element

    Rod Snyder, May 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    538
    Vidar Petursson
    May 29, 2004
  3. Replies:
    4
    Views:
    2,318
  4. Chris Smith
    Replies:
    1
    Views:
    1,028
    Adam Maass
    May 16, 2005
  5. diegomrosa
    Replies:
    6
    Views:
    44,582
    Roedy Green
    Nov 19, 2005
  6. Mr. x
    Replies:
    3
    Views:
    976
  7. Robin Siebler
    Replies:
    4
    Views:
    31,286
    Tim Peters
    Oct 8, 2004
  8. HANM
    Replies:
    2
    Views:
    1,528
    Joseph Kesselman
    Jan 29, 2008
Loading...