incorporate variable into object names
Posted: Sun Dec 13, 2009 5:38 am
Hi
I am learning how to access other windows using JavaScript and the code below works just fine but what I would like to do is run through a for loop that changes a variable car into car1 to car2, car 3 etc - BUT can't work out how to incorporate the variable car into the places where I currently have car1 into the code block?
Any help very welcome!
I am learning how to access other windows using JavaScript and the code below works just fine but what I would like to do is run through a for loop that changes a variable car into car1 to car2, car 3 etc - BUT can't work out how to incorporate the variable car into the places where I currently have car1 into the code block?
Any help very welcome!
Code: Select all
<script type="text/javascript">
// This function checked whether the car is already checked on the main window or not.
// Then, it toggles the status of the checkbox accordingly
function process()
{
//want a for loop that replaces car1 in the code below into car1, car2, car3 .... but how ?
if (opener.document.forms[0].car1.checked)
{
opener.document.forms[0].car1.checked = false;
document.getElementById("car1").innerHTML="[add]";
}
else {
opener.document.forms[0].car1.checked = true;
document.getElementById("car1").innerHTML="[remove]";
}
}
</script>