...

View Full Version : loop through form elements wiith an id



nikko50
10-13-2011, 01:21 AM
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

}

Old Pedant
10-13-2011, 06:03 AM
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 );
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum