Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    392
    Thanks
    77
    Thanked 0 Times in 0 Posts

    loop through form elements wiith an id

    Hi all.

    I have a form named "theForm". How can I loop through this form elements that have an "id" ATTRIBUTE to them and then populate my ids array?


    var ids = new Array;

    for(i=0; i<document.theForm.elements.length; i++)
    {

    IF ELEMENT HAS AN ID ATTRIBUTE POPULATE ids array

    }
    Last edited by nikko50; 10-13-2011 at 01:34 AM.

  2. #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    29,698
    Thanks
    93
    Thanked 4,947 Times in 4,908 Posts
    Code:
    var ids = [ ];
    
    var form = document.theForm;
    
    for( i=0; i  < form.elements.length; i++ )
    {
        var elem = form.elements[i];
        if ( elem.id != null && elem.id != "" )
        {
            ids.push( elem.id );
        }
    }
    Be yourself. No one else is as qualified.


 

Posting Permissions

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