Connecting Tech Pros Worldwide Help | Site Map

For loop error - object expected

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 07:52 PM
undercups
Guest
 
Posts: n/a
Default For loop error - object expected

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, 07:53 PM
Lee
Guest
 
Posts: n/a
Default 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, 07:53 PM
RobG
Guest
 
Posts: n/a
Default 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, 07:53 PM
undercups
Guest
 
Posts: n/a
Default Re: For loop error - object expected

thanks guys

Duncan

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.