darren-w
08-27-2009, 03:40 PM
Hi,
I would like to run a foreach loop for DOM elements and substitute in vars from an array, here is an example of the concept
//this checks if a box is checked and alerts if it is...
var testItem=array("item1","frog","bone")
for (i in testItem)
{
if (document.form.testItem[i].checked) alert("is checked");
}
I think I am missing out something really fundamental here I've tried appending with + eg "document.form.+testItem[i]+.checked" but this is wrong.
Can this be done?
Darren
I would like to run a foreach loop for DOM elements and substitute in vars from an array, here is an example of the concept
//this checks if a box is checked and alerts if it is...
var testItem=array("item1","frog","bone")
for (i in testItem)
{
if (document.form.testItem[i].checked) alert("is checked");
}
I think I am missing out something really fundamental here I've tried appending with + eg "document.form.+testItem[i]+.checked" but this is wrong.
Can this be done?
Darren