[Webinar] Streamline your web hosting managementRegister Today


Error referring to form field

Posted on 2007-03-22
Medium Priority
Last Modified: 2012-05-05
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();
$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) {
//var lead = document.new.building;    

//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>
$query = "SELECT * FROM managers ORDER BY name";
$result = mysql_query($query) or die(mysql_error());
      $manager = mysql_fetch_array($result);
      <option value="<?php echo $manager['id'] ?>"><?php echo $manager['name'] ?></option>
<td>Senior Manager:</td>
<td><select name='mgrleader' class='ta' value="<?php echo $leader ?>">
<option selected></option>
<option>Select a manager</option>

I am sorry I don't have very many points to use on this question...
Question by:JJ123
  • 3
LVL 15

Expert Comment

ID: 18776221
I think the problem is here:


You have a mgr_leader select tag, but you don't seem to have a "leader" object anywhere.

Author Comment

ID: 18780047
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){

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

Author Comment

ID: 18794581
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)

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

<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>
<td>Senior Manager:</td>
<td><select name='mgr_leader' class='ta' value="">
<option selected></option>
<option>Select a manager</option>

Accepted Solution

JJ123 earned 0 total points
ID: 18795237
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.


Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question