Dylan Leblanc
05-29-2003, 11:00 PM
I have an array (called myArray in the example) which contains information about all the checkboxes and such on the search form.
I am looping through the array and setting the onclick for each checkbox. Here is a way to do this: document.search.status[0].onclick = function() { StatusChecked('all', 0) }
But my problem is that the 0 that is being passed to the StatusChecked() function needs to actually be a dynamic value. Each time through the loop that value needs to be changed. But as far as I can tell, if I substitute it for a variable, it doesn't work. i understand why it doesn't work this way, but can't figure out an alternative way that does work.
You can see in the second line is StatusChecked('all', index), but that is not going to work. What can I do?
for (index = 0; index < myArray.length; index++) {
document.search[myArray[index]['name'] + 'All'].onclick = function() { StatusChecked('all', index); }
for (i = 0; i < document.search[myArray[index]['name'] + '[]'].length; i ++) {
document.search[myArray[index]['name'] + '[]'][i ].onclick = function() { StatusChecked(this, i); }
}
}
I thought maybe something like onclick = function(var i = index) { StatusChecked('all', i); } might do the trick, but no.
I am looping through the array and setting the onclick for each checkbox. Here is a way to do this: document.search.status[0].onclick = function() { StatusChecked('all', 0) }
But my problem is that the 0 that is being passed to the StatusChecked() function needs to actually be a dynamic value. Each time through the loop that value needs to be changed. But as far as I can tell, if I substitute it for a variable, it doesn't work. i understand why it doesn't work this way, but can't figure out an alternative way that does work.
You can see in the second line is StatusChecked('all', index), but that is not going to work. What can I do?
for (index = 0; index < myArray.length; index++) {
document.search[myArray[index]['name'] + 'All'].onclick = function() { StatusChecked('all', index); }
for (i = 0; i < document.search[myArray[index]['name'] + '[]'].length; i ++) {
document.search[myArray[index]['name'] + '[]'][i ].onclick = function() { StatusChecked(this, i); }
}
}
I thought maybe something like onclick = function(var i = index) { StatusChecked('all', i); } might do the trick, but no.