Page 1 of 1

handling input array names

Posted: Tue Mar 14, 2006 9:07 am
by kendall
hello,

i didnt really know how to term this issue so please excuse me...

i have several checkboxes all id as

Code: Select all

<input type="checkbox" id="region[]" name="region[]" />
How does javascript access an element with id like that?
Kendall

Posted: Tue Mar 14, 2006 10:16 am
by feyd
It doesn't very easily, sorta. getElementsByTagName can pull up an arrary of the checkboxes. the id attribute is supposed to be unique. So if you created them in a linear way (say region1, region2, region3) you could iterate over them quite easilying using getElementById then:

Code: Select all

var foo = 1;
while(bar = document.getElementById('region'+(foo++)))
{
  // do something
}