I have a file say "a.php", where in I have declared multiple select boxes with same name but different id's .
I would like to access these from javascript in a for loop(auto loop, as i can have many like item1, item2,...itemn) .
a.php
<html>
...
<form ... >
..
<select name="item[]" id="item1"> ..</select>
<select name="item[]" id="item2"> ..</select>
<select name="item[]" id="item3"> ..</select>
</form>
..
</html>
I tried to access these using the following code but it gives me error :
var c;
for (i=0; i<n; i++) {
c = "item" + i.toString()
if (document.newVoucher.getElementById(c).value!="-1") {
// do something
}
}
Although c gives me the right value but I am not sure if its the right type as it does not work.
Note that I cant change the name (from 'item[]' to 'item') since I use them in PHP.
Although I did be happy to access the elements by name ( i tried using document.form[0].item[][index] ) but it did not work.