Forum Moderators: open

Message Too Old, No Replies

Missing ; before statement - stops all code execution

         

wheels

11:55 pm on May 2, 2008 (gmt 0)

10+ Year Member



Here is the method

[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

httpwebwitch

12:14 am on May 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try doing this without using eval().

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]];

wheels

12:21 am on May 4, 2008 (gmt 0)

10+ Year Member



here's my method now:


[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.

mehh

3:27 pm on May 4, 2008 (gmt 0)

10+ Year Member



looks tke you are giving it a function in the org_ids array hence the firebug error
document.remote_form.organization_function (iterator) {\n

check the array you're passing it and add a type check
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;
}
}