SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a form on one of my pages and I am trying to make an auto-tab function where it checks when you get to the end of a field it automatically tabs to the next and so far so good but what I want to do is to get the array index for a given element which I supply the name for instance

    document.forms[0].elements["dd"];

    Where dd is a field in my form, how can I get the number of the element or
    document.forms[0].elements[6];
    automatically can I convert it somehow.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2000
    Location
    Warwickshire, England
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would document.forms[0].elements[0].name be what you are looking for? or are you looking to convert the name into index?

  3. #3
    SitePoint Evangelist
    Join Date
    Jul 2000
    Location
    Warwickshire, England
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    aha.. I think you will have to use the name property and something like..

    function getIndex(what,which)
    {
    for (var i=0;i < what.elements.length;i++)
    {
    if (what.elements[ i ].name == which) {return i;}
    }
    return -1;
    }

    alert( getIndex(document.forms[0], "dd") );

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why yes thanks
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •