Connecting Tech Pros Worldwide Forums | Help | Site Map

For loop error - object expected

undercups
Guest
 
Posts: n/a
#1: Jul 23 '05
When I run page I immediatley get "Object expected" message and the tag
<body onload="setfocus()" is highlighted.

The error occurs in this snippet from within the script file

function validatePage()
{
// select the items in the TeamDivisions listbox
var i=document.TeamMaintenance.TeamDivisions.options.l ength -1
For (i; i>=0; i--)
{document.TeamMaintenance.hiddenTeamDivisions.valu e +=
document.TeamMaintenance.TeamDivisions.options[i].value;
document.TeamMaintenance.hiddenTeamDivisions.value += ",";}

// Now validate the page
return validatePanels();
}

I know this because if I comment out the line "For (i; i>=0;i--)", the
functions within the script file work correctly. Obviosusly in the
above snippet the 2 lines to be executed within the For loop executes
the once but I get the expected value in the hiddenTeamDivisions
control so at least it shows that these lines do work.
The problem is why do I get the "object expected" message when this
line is not commented out?

Thanks in anticipation

Duncan


Lee
Guest
 
Posts: n/a
#2: Jul 23 '05

re: For loop error - object expected


undercups said:[color=blue]
>
>When I run page I immediatley get "Object expected" message and the tag
><body onload="setfocus()" is highlighted.
>
>The error occurs in this snippet from within the script file
>
>function validatePage()
>{
>// select the items in the TeamDivisions listbox
> var i=document.TeamMaintenance.TeamDivisions.options.l ength -1
> For (i; i>=0; i--)[/color]


The keyword is "for", not "For".

RobG
Guest
 
Posts: n/a
#3: Jul 23 '05

re: For loop error - object expected


undercups wrote:[color=blue]
> When I run page I immediatley get "Object expected" message and the tag
> <body onload="setfocus()" is highlighted.
>
> The error occurs in this snippet from within the script file
>
> function validatePage()
> {
> // select the items in the TeamDivisions listbox
> var i=document.TeamMaintenance.TeamDivisions.options.l ength -1
> For (i; i>=0; i--)
> {document.TeamMaintenance.hiddenTeamDivisions.valu e +=
> document.TeamMaintenance.TeamDivisions.options[i].value;
> document.TeamMaintenance.hiddenTeamDivisions.value += ",";}
>[/color]

Try this:

// select the items in the TeamDivisions listbox
var x = [];
var f = document.TeamMaintenance.TeamDivisions.options;
var i = f.length;
while (i--){ x.push(f[i].value) }
document.TeamMaintenance.hiddenTeamDivisions.value = x.join(',');
[color=blue]
> // Now validate the page
> return validatePanels();
> }
>[/color]
[...]



--
Rob
undercups
Guest
 
Posts: n/a
#4: Jul 23 '05

re: For loop error - object expected


thanks guys

Duncan

Closed Thread