[Javascript] Re:Selects and Arrays

Mckinney, Lori K lkmckinn at ingr.com
Fri Nov 16 16:54:52 CST 2001


Bill, 

Is this just a typo in your mail?  Shouldn't it be ==?

      if ( filter = sprayChoice[i][3])

-----Original Message-----
From: Bill Marriott [mailto:bill.marriott at optusnet.com.au]
Sent: Friday, November 16, 2001 4:30 PM
To: javascript at LaTech.edu
Subject: [Javascript] Re:Selects and Arrays


Hi Everyone,

I'm having trouble with dynaically adding options to a second select
depending on the choice of the first select.
Can anyone see why the code below dosen't work.
(It works without the "for" looping. )

thanks
Bill

var sprayChoice = new Array();

      sprayChoice[0]= new Array();
           sprayChoice[0][0]=13;
           sprayChoice[0][1]="Cosmos";
           sprayChoice[0][2]=4;

      sprayChoice[1]= new Array();
           sprayChoice[1][0]=9;
           sprayChoice[1][1]="DAP";
           sprayChoice[1][2]=3;

      sprayChoice[2]= new Array();
           sprayChoice[2][0]=1;
           sprayChoice[2][1]="Glysophate 450";
           sprayChoice[2][2]=1;

      sprayChoice[3]= new Array();
           sprayChoice[3][0]=11;
           sprayChoice[3][1]="Lorsban";
           sprayChoice[3][2]=2;

      sprayChoice[4]= new Array();
           sprayChoice[4][0]=8;
           sprayChoice[4][1]="MAP";
           sprayChoice[4][2]=3;

      sprayChoice[5]= new Array();
           sprayChoice[5][0]=10;
           sprayChoice[5][1]="Red Pickle";
           sprayChoice[5][2]=4;

      sprayChoice[6]= new Array();
           sprayChoice[6][0]=7;
           sprayChoice[6][1]="Spray seed";
           sprayChoice[6][2]=1;

      sprayChoice[7]= new Array();
           sprayChoice[7][0]=12;
           sprayChoice[7][1]="Talstar";
           sprayChoice[7][2]=2;


var totalRows=8;
var filter = 0 ;

function setProductOptions()
{
 filter=document.newTable.sprayType.value;
 var i;
  for (i=0; i=totalRows; i++)
   {
      if ( filter = sprayChoice[i][3])
         {
           var pOption=document.createElement("OPTION");
           pOption.value=sprayChoice[i][0];
           pOption.text=sprayChoice[i][1];
           document.newTable.SPRAYPRODUCT.options.add(pOption);
         }
   }
}
</SCRIPT>

<tr ID="sprayRow">
            <td width="13%">
              <select size="1" name="sprayType"
onChange="setProductOptions()">
               <option selected value=""></option>

      <option value=3>Fertilizer</option>

      <option value=1>Herbicide</option>

      <option value=2>Insecticide</option>

      <option value=4>Seed Treatment</option>

               </select>
            </td>
            <td width="14%">
              <select size="1" name="SPRAYPRODUCT" ID="selectSprayProd" >
               <option selected value=""></option>
               </select>
            </td>

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
http://www.LaTech.edu/mailman/listinfo/javascript



More information about the Javascript mailing list