[Javascript] Re:Selects and Arrays
Bill Marriott
bill.marriott at optusnet.com.au
Fri Nov 16 16:29:49 CST 2001
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>
More information about the Javascript
mailing list