Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-13-2011, 01:21 AM   PM User | #1
nikko50
Regular Coder

 
Join Date: May 2004
Posts: 375
Thanks: 62
Thanked 0 Times in 0 Posts
nikko50 is an unknown quantity at this point
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..
nikko50 is offline   Reply With Quote
Old 10-13-2011, 06:03 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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 );
    }
}
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:44 PM.


Advertisement
Log in to turn off these ads.