Connecting Tech Pros Worldwide Help | Site Map

For loop error - object expected

  #1  
Old July 23rd, 2005, 08:52 PM
undercups
Guest
 
Posts: n/a
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

  #2  
Old July 23rd, 2005, 08:53 PM
Lee
Guest
 
Posts: n/a

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

  #3  
Old July 23rd, 2005, 08:53 PM
RobG
Guest
 
Posts: n/a

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
  #4  
Old July 23rd, 2005, 08:53 PM
undercups
Guest
 
Posts: n/a

re: For loop error - object expected


thanks guys

Duncan

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft VBScript compilation error: Expected ' kevinr answers 2 September 19th, 2009 04:30 PM
For loop containing HTML JWest46088 answers 4 February 14th, 2008 10:47 PM
redefinition inside for loop pauldepstein@att.net answers 9 October 28th, 2007 10:25 AM
For loop help yoshi answers 2 December 21st, 2006 05:48 AM
using a for loop to determine maximum value of an int variable garyusenet@myway.com answers 29 December 11th, 2006 12:05 AM