Error referring to form field

I have some JavaScript that I can't seem to get to work. I will insert my code to show you what I am doing. The commented part seems to be the problem although I could definately be wrong. As soon as I uncomment them, I am getting an error 'object expected'. Otherwise the alert works fine.

here is the functions

var leaderArray = new Array();
<?PHP
$query = "SELECT * FROM managers order by name";    
$result = mysql_query($query);
while( $row = mysql_fetch_array($result) )
{  
       $query2 = "SELECT * FROM managers WHERE name = '".$row['name']."'";
       $result2 = mysql_query($query2);      
       echo "leaderArray[".$row['id']."] = new Array();\n";    
       while( $row2 = mysql_fetch_array($result2) ){
              echo "leaderArray[".$row['id']."].push('".$row2['leader']."');\n";          
      }
}
?>  

function Fill_Sub(inputManager) {
alert(inputManager);
//var lead = document.new.building;    
//mgr_leader.options.length=0;  

//for(var no=0;no<leaderArray[inputManager].length;no++)//{    
//mgr_leader.options[leader.options.length] = new Option(leaderArray[inputManager][no],leaderArray[inputManager][no]);    
//}      
}

Here is the fields in the form:
<tr><td width="95">Manager:</td>
<td><select name='manager' class='ta' onchange="Fill_Sub(this.options[this.selectedIndex].value);">
<option selected><?php echo $manager ?></option>
<?php
$query = "SELECT * FROM managers ORDER BY name";
$result = mysql_query($query) or die(mysql_error());
for($i=0;$i<mysql_numrows($result);$i++)
{
      $manager = mysql_fetch_array($result);
      ?>
      <option value="<?php echo $manager['id'] ?>"><?php echo $manager['name'] ?></option>
      <?php
}
?>
</select></td>
<td>Senior Manager:</td>
<td><select name='mgrleader' class='ta' value="<?php echo $leader ?>">
<option selected></option>
<option>Select a manager</option>
</select>
</td></tr>

I am sorry I don't have very many points to use on this question...
LVL 1
JJ123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

stanscott2Commented:
I think the problem is here:

//mgr_leader.options[leader.options.length]

You have a mgr_leader select tag, but you don't seem to have a "leader" object anywhere.
0
JJ123Author Commented:
That probably was a problem. I've changed it. But as soon as I take the commenting off of the line where I am creating the variable lead, I get an error - "Expected Identifier". Is there something wrong with that line specifically?

function Fill_Sub(inputManager){
alert(inputManager);

var lead = document.new.mgr_leader;    
//lead.options.length=0;  
      
//for(var no=0;no<leaderArray[inputManager].length;no++)//{    
//lead.options[lead.options.length] = new Option(leaderArray[inputManager][no],leaderArray[inputManager][no]);    
//}
      
}
0
JJ123Author Commented:
maybe seeing the source would help...
...
var leaderArray = new Array();
leaderArray[1] = new Array();
leaderArray[1].push('Mike Thomas');
leaderArray[2] = new Array();
leaderArray[2].push('Scott Wilcocks');
leaderArray[3] = new Array();
leaderArray[3].push('Brent Selin');
leaderArray[4] = new Array();
leaderArray[4].push('Colin McIntyre');
leaderArray[5] = new Array();
leaderArray[5].push('Scott Wilcocks');
leaderArray[6] = new Array();
leaderArray[6].push('Amy-Jo Strutt');
leaderArray[7] = new Array();
leaderArray[7].push('Scott Wilcocks');
leaderArray[8] = new Array();
leaderArray[8].push('Karen Sonntag');
leaderArray[9] = new Array();
leaderArray[9].push('Scott Wilcocks');
leaderArray[10] = new Array();
leaderArray[10].push('Brent Selin');
leaderArray[11] = new Array();
leaderArray[11].push('Colin McIntyre');
leaderArray[12] = new Array();
leaderArray[12].push('Brian Salmond');
leaderArray[13] = new Array();
leaderArray[13].push('Brent Selin');
leaderArray[14] = new Array();
leaderArray[14].push('Brad Krill');
leaderArray[15] = new Array();
leaderArray[15].push('Scott Wilcocks');
leaderArray[16] = new Array();
leaderArray[16].push('Scott Wilcocks');
leaderArray[17] = new Array();
leaderArray[17].push('Brenda Nielsen');
leaderArray[18] = new Array();
leaderArray[18].push('John Hickman');
leaderArray[19] = new Array();
leaderArray[19].push('Richard Bothe');
leaderArray[20] = new Array();
leaderArray[20].push('Brent Selin');
leaderArray[21] = new Array();
leaderArray[21].push('John Hickman');
leaderArray[22] = new Array();
leaderArray[22].push('Brent Selin');
leaderArray[23] = new Array();
leaderArray[23].push('Richard Bothe');
leaderArray[24] = new Array();
leaderArray[24].push('Brad Krill');
leaderArray[25] = new Array();
leaderArray[25].push('Sian Roberts');
leaderArray[26] = new Array();
leaderArray[26].push('Mike Thomas');
leaderArray[27] = new Array();
leaderArray[27].push('Mike Thomas');
leaderArray[28] = new Array();
leaderArray[28].push('Mike Thomas');
leaderArray[29] = new Array();
leaderArray[29].push('Scott Wilcocks');
leaderArray[30] = new Array();
leaderArray[30].push('John Hickman');
leaderArray[31] = new Array();
leaderArray[31].push('Jeni Johnson');
leaderArray[32] = new Array();
leaderArray[32].push('John Hickman');
leaderArray[33] = new Array();
leaderArray[33].push('Scott Wilcocks');
leaderArray[34] = new Array();
leaderArray[34].push('Scott Wilcocks');
leaderArray[35] = new Array();
leaderArray[35].push('Scott Wilcocks');
leaderArray[36] = new Array();
leaderArray[36].push('Scott Wilcocks');
leaderArray[37] = new Array();
leaderArray[37].push('Karen Sonntag');
leaderArray[38] = new Array();
leaderArray[38].push('Michael Clarke');
leaderArray[39] = new Array();
leaderArray[39].push('Karen Sonntag');
leaderArray[40] = new Array();
leaderArray[40].push('Sian Roberts');
leaderArray[41] = new Array();
leaderArray[41].push('John Hickman');
leaderArray[42] = new Array();
leaderArray[42].push('Sian Roberts');
leaderArray[43] = new Array();
leaderArray[43].push('Trieu Vo');
leaderArray[44] = new Array();
leaderArray[44].push('Brenda Nielsen');
leaderArray[45] = new Array();
leaderArray[45].push('Scott Wilcocks');
leaderArray[46] = new Array();
leaderArray[46].push('Scott Wilcocks');
leaderArray[47] = new Array();
leaderArray[47].push('John Hickman');
leaderArray[48] = new Array();
leaderArray[48].push('Amy-Jo Strutt');
leaderArray[49] = new Array();
leaderArray[49].push('Scott Wilcocks');
leaderArray[50] = new Array();
leaderArray[50].push('Mike Thomas');
leaderArray[51] = new Array();
leaderArray[51].push('Trieu Vo');
leaderArray[52] = new Array();
leaderArray[52].push('Kieran Gunning');
leaderArray[53] = new Array();
leaderArray[53].push('Sian Roberts');
leaderArray[54] = new Array();
leaderArray[54].push('Brenda Nielsen');
leaderArray[55] = new Array();
leaderArray[55].push('Scott Wilcocks');
leaderArray[56] = new Array();
leaderArray[56].push('Jeni Johnson');
leaderArray[57] = new Array();
leaderArray[57].push('Amy-Jo Strutt');
 

function Fill_Sub(inputManager)
{
      alert(inputManager);

          var lead = document.new.mgr_leader;    
          //lead.options.length=0;  
      
          //for(var no=0;no<leaderArray[inputManager].length;no++)
      //{    
            //lead.options[lead.options.length] = new Option(leaderArray[inputManager][no],leaderArray[inputManager][no]);    
      //}
      
}
-->
</script>

....
<tr><td width="95">Manager:</td>
<td><select name='manager' class='ta' onchange="Fill_Sub(this.options[this.selectedIndex].value);">
<option selected></option>
      <option value="1">Aaron Fraser</option>
            <option value="2">Amy-Jo Strutt</option>
            <option value="3">Bill Hoffart</option>
            <option value="4">Brad Greenhorn</option>
            <option value="5">Brad Krill</option>
            <option value="6">Brenda Nielsen</option>
            <option value="7">Brent Selin</option>
            <option value="8">Brian McClure</option>
            <option value="9">Brian Salmond</option>
            <option value="10">Chris Graham</option>
            <option value="11">Chris Metcalfe</option>
            <option value="12">Colin McIntyre</option>
            <option value="13">Dave Morris</option>
            <option value="14">David Woo</option>
            <option value="15">Dean Bisset</option>
            <option value="16">Dean Bissett</option>
            <option value="17">Debbie Coulter</option>
            <option value="18">Debbie Craig</option>
            <option value="19">Doug Hudgeon</option>
            <option value="20">Eric Baethke</option>
            <option value="21">Eric Winter</option>
            <option value="22">Ernie Mah</option>
            <option value="23">Florrie Drake</option>
            <option value="24">Frank Fida</option>
            <option value="25">Gary Dobransky</option>
            <option value="26">Jag Gill</option>
            <option value="27">James Markwart</option>
            <option value="28">Jamie Broughton</option>
            <option value="29">Jeni Johnson</option>
            <option value="30">Jesse Parker</option>
            <option value="31">Jodi Baker</option>
            <option value="32">John Gardippe</option>
            <option value="33">John Hankins</option>
            <option value="34">John Hickman</option>
            <option value="35">Karen Sonntag</option>
            <option value="36">Kelly Hoondal</option>
            <option value="37">Kelly Houston</option>
            <option value="38">Kieran Gunning</option>
            <option value="39">Kirk Hennel</option>
            <option value="40">Kristine McIntyre</option>
            <option value="41">Linda Guo</option>
            <option value="42">Mark Hinman</option>
            <option value="43">Mark Kelman</option>
            <option value="44">Mike Neumann</option>
            <option value="45">Mike Thomas</option>
            <option value="46">Pearl Doerksen</option>
            <option value="47">Phil Coulombe</option>
            <option value="48">Richard Bothe</option>
            <option value="49">Robert Seddon</option>
            <option value="50">Roberta Tobin</option>
            <option value="51">Roy Joseph</option>
            <option value="52">Scott Willcocks</option>
            <option value="53">Sergio Reveles</option>
            <option value="54">Sharon Field</option>
            <option value="55">Sian Roberts</option>
            <option value="56">Teresa Darcangelo</option>
            <option value="57">Trieu Vo</option>
      </select></td>
<td>Senior Manager:</td>
<td><select name='mgr_leader' class='ta' value="">
<option selected></option>
<option>Select a manager</option>
</select>
</td></tr>
....
0
JJ123Author Commented:
Well it looks like I just solved the issue. The page was named 'new' and Java didn't seem to like that. I renamed it and it is now working just fine. Thanks for trying to help stanscott2 but I am going to try to recover my points.

JJ123
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.