For loop error - object expected

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • undercups

    #1

    For loop error - object expected

    When I run page I immediatley get "Object expected" message and the tag
    <body onload="setfocu s()" 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.Team Maintenance.Tea mDivisions.opti ons.length -1
    For (i; i>=0; i--)
    {document.TeamM aintenance.hidd enTeamDivisions .value +=
    document.TeamMa intenance.TeamD ivisions.option s[i].value;
    document.TeamMa intenance.hidde nTeamDivisions. 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 hiddenTeamDivis ions
    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

    #2
    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="setfocu s()" 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.Team Maintenance.Tea mDivisions.opti ons.length -1
    > For (i; i>=0; i--)[/color]


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

    Comment

    • RobG

      #3
      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="setfocu s()" 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.Team Maintenance.Tea mDivisions.opti ons.length -1
      > For (i; i>=0; i--)
      > {document.TeamM aintenance.hidd enTeamDivisions .value +=
      > document.TeamMa intenance.TeamD ivisions.option s[i].value;
      > document.TeamMa intenance.hidde nTeamDivisions. value += ",";}
      >[/color]

      Try this:

      // select the items in the TeamDivisions listbox
      var x = [];
      var f = document.TeamMa intenance.TeamD ivisions.option s;
      var i = f.length;
      while (i--){ x.push(f[i].value) }
      document.TeamMa intenance.hidde nTeamDivisions. value = x.join(',');
      [color=blue]
      > // Now validate the page
      > return validatePanels( );
      > }
      >[/color]
      [...]



      --
      Rob

      Comment

      • undercups

        #4
        Re: For loop error - object expected

        thanks guys

        Duncan

        Comment

        Working...