Get ordinal of form element

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • stewartfip@yahoo.com

    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="javas cript">
    function disp_val(objFie ld){
    alert(---the ordinal of objField in form---)
    }
    </script>
    <body>
    <form>
    <input type="text" onblur="disp_va l(this)"><br>
    <input type="text" onblur="disp_va l(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+.

  • Martin Honnen

    #2
    Re: Get ordinal of form element



    stewartfip@yaho o.com wrote:
    [color=blue]
    > How do I get the ordinal of a form element from a reference to the
    > object itself.
    >
    > For example:
    >
    > <html>
    > <script language="javas cript">
    > function disp_val(objFie ld){
    > alert(---the ordinal of objField in form---)[/color]

    You need a loop:

    var form;
    if ((form = objField.form)) {
    for (var i = 0; i < form.elements.l ength; i++) {
    if (objField == form.elements[i]) {
    alert('index is ' + i);
    break;
    }
    }
    }

    --

    Martin Honnen

    Comment

    • stewartfip@yahoo.com

      #3
      Re: Get ordinal of form element

      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

      Comment

      Working...