Forum Moderators: open
[4]
function selectAllForTemplateList(org_ids, group_types){
select_all = document.remote_form.select_all;
for(i in org_ids){
box = eval("document.remote_form.organization_" + org_ids[i]);
box.checked = select_all.checked;
}
for(j in group_types){
gbox = eval("document.remote_form.group_type_" + group_types[j]);
gbox.checked = select_all.checked;
}
alert(group_types[2]);
}
[/4]
The org_ids variable is an array of integers and group_types is an array of strings. Both blocks work fine independently.
I get the 'missing ; before statement' error on line 4. The first block works properly but the error causes the second block to not be executed. If I swap the blocks only the first one is executed and I get the same error.
Firebug also spit this out saying it's where the error is:
document.remote_form.organization_function (iterator) {\n
I am mystified. I even tried breaking this up into two separate functions but only the first one gets executed.
Thanks in advance,
Aaron
eval() is useful sometimes, but so often it causes mysterious syntax errors, it's worth weaning onesself from using it too often, esp. when it's not needed.
you can use array notation instead of dot notation to access your obejcts:
document.remote_form['organization_' + org_ids[i]];
[4]
function selectAllForTemplateList(org_ids, group_types){
select_all = document.remote_form.select_all;
for(i in org_ids){
box = document.remote_form["organization_" + org_ids[i]];
box.checked = select_all.checked;
}
for(j in group_types){
gbox = document.remote_form["group_type_" + group_types[j]];
gbox.checked = select_all.checked;
}
}
[/4]
now i get 'box has no properties' on line 5, even though it works. still stops the execution of the second block.
document.remote_form.organization_function (iterator) {\n
function selectAllForTemplateList(org_ids, group_types){
var i,select_all = document.remote_form.select_all;
for(i in org_ids){
if(typeof(i)=="string")
document.remote_form["organization_" + org_ids[i]].checked = select_all.checked;
}
for(i in group_types){
if(typeof(i)=="string")
document.remote_form["group_type_" + group_types[i]].checked = select_all.checked;
}
}