Hi, I created a couple of arrays to store some values.Based on a value selected from ccy select box, I want to populate the corresponding
array into the stgy select box.If I choose another value from ccy select box, I want to be able to remove the
existing value from the stgy select box and populate the second array into it.
This code is not working.Please help me.
Thanks,
<HTML><BODY>
<FORM Name=”Test”>
<SELECT Name=”ccy” onChange=”fillstgy();”>
<option value=”1″>TKY</option>
<option value=”2″>EUR</option>
<option value=”3″>AUD</option>
<option value=”4″>USD</option>
</SELECT>
<SELECT Name=”stgy” >
<option value=”1″>select</option>
</SELECT>
</FORM>
<SCRIPT>
var stgyTKY=new Array();
stgyTKY[0]=”TKY1″;
stgyTKY[1]=”TKY2″;
stgyTKY[2]=”TKY3″;
var stgyEUR=new Array();
stgyEUR[0]=”EUR1″;
stgyEUR[1]=”EUR2″;
stgyEUR[2]=”EUR3″;
var frm = document.Test;
// fill a select from contents of an array!
function fill( sel, ar )
{
var ix;
for ( ix = sel.options.length-1; ix >= 0; –ix )
sel.options[ix] = null;
alert(“removing elements”);
for ( ix = 0; ix < ar.length; ++ix )
sel.options[ix] = new Option( ar[ix][0], ar[ix][1] );
alert(“adding elements”);
}
function fillstgy()
{
if(document.forms[0].ccy.selectedIndex == 0)
{
alert(“JPY”);
TKY = stgyTKY;
fill( frm.stgy, TKY );
}
else if(document.forms[0].ccy.selectedIndex == 1)
{
alert(“EUR”);
EUR = stgyEUR
fill( frm.stgy, EUR );
}
}
</SCRIPT>
</BODY></HTML>