Here is some code that may help you:
<HEAD>
<script type="text/javascript">
<!--
var arrItems1 = new Array();
var arrItemsGrp1 = new Array();
arrItems1[3] = "Truck";
arrItemsGrp1[3] = 1;
arrItems1[4] = "Train";
arrItemsGrp1[4] = 1;
arrItems1[5] = "Car";
arrItemsGrp1[5] = 1;
arrItems1[6] = "Boat";
arrItemsGrp1[6] = 2;
arrItems1[7] = "Submarine" ;
arrItemsGrp1[7] = 2;
arrItems1[0] = "Planes";
arrItemsGrp1[0] = 3;
arrItems1[1] = "Ultralight ";
arrItemsGrp1[1] = 3;
arrItems1[2] = "Glider";
arrItemsGrp1[2] = 3;
var arrItems2 = new Array();
var arrItemsGrp2 = new Array();
arrItems2[21] = "747";
arrItemsGrp2[21] = 0
arrItems2[22] = "Cessna";
arrItemsGrp2[22] = 0
arrItems2[31] = "Kolb Flyer";
arrItemsGrp2[31] = 1
arrItems2[34] = "Kitfox";
arrItemsGrp2[34] = 1
arrItems2[35] = "Schwietzer Glider";
arrItemsGrp2[35] = 2
arrItems2[99] = "Chevy Malibu";
arrItemsGrp2[99] = 5
arrItems2[100] = "Lincoln LS";
arrItemsGrp2[100] = 5
arrItems2[57] = "BMW Z3";
arrItemsGrp2[57] = 5
arrItems2[101] = "F-150";
arrItemsGrp2[101] = 3
arrItems2[102] = "Tahoe";
arrItemsGrp2[102] = 3
arrItems2[103] = "Freight Train";
arrItemsGrp2[103] = 4
arrItems2[104] = "Passenger Train";
arrItemsGrp2[104] = 4
arrItems2[105] = "Oil Tanker";
arrItemsGrp2[105] = 6
arrItems2[106] = "Fishing Boat";
arrItemsGrp2[106] = 6
arrItems2[200] = "Los Angelas Class";
arrItemsGrp2[200] = 7
arrItems2[201] = "Kilo Class";
arrItemsGrp2[201] = 7
arrItems2[203] = "Seawolf Class";
arrItemsGrp2[203] = 7
function selectChange(co ntrol, controlToPopula te, ItemArray,
GroupArray) {
var myEle ;
var x ;
// Empty the second drop down box of any choices
for (var q=controlToPopu late.options.le ngth;q>=0;q--)
controlToPopula te.options[q]=null;
if (control.name == "firstChoic e") {
// Empty the third drop down box of any choices
for (var q=form.thirdCho ice.options.len gth;q>=0;q--)
form.thirdChoic e.options[q] = null;
}
// ADD Default Choice - in case there are no values
myEle = document.create Element("option ") ;
myEle.value = 0 ;
myEle.text = "[SELECT]" ;
// controlToPopula te.add(myEle) ;
controlToPopula te.appendChild( myEle)
// Now loop through the array of individual items
// Any containing the same child id are added to
// the second dropdown box
for ( x = 0 ; x < ItemArray.lengt h ; x++ ) {
if ( GroupArray[x] == control.value ) {
myEle = document.create Element("option ") ;
//myEle.value = x ;
myEle.setAttrib ute('value',x);
// myEle.text = ItemArray[x] ;
var txt = document.create TextNode(ItemAr ray[x]);
myEle.appendChi ld(txt)
// controlToPopula te.add(myEle) ;
controlToPopula te.appendChild( myEle)
}
}
}
function selectChange(co ntrol, controlToPopula te, ItemArray,
GroupArray) {
var myEle ;
var x ;
// Empty the second drop down box of any choices
for (var q=controlToPopu late.options.le ngth;q>=0;q--)
controlToPopula te.options[q]=null;
if (control.name == "firstChoic e") {
// Empty the third drop down box of any choices
for (var q=form.thirdCho ice.options.len gth;q>=0;q--)
form.thirdChoic e.options[q] = null;
}
// ADD Default Choice - in case there are no values
myEle=document. createElement(" option");
theText=documen t.createTextNod e("[SELECT]");
myEle.appendChi ld(theText);
myEle.setAttrib ute("value","0" );
controlToPopula te.appendChild( myEle);
// Now loop through the array of individual items
// Any containing the same child id are added to
// the second dropdown box
for ( x = 0 ; x < ItemArray.lengt h ; x++ ) {
if ( GroupArray[x] == control.value ) {
myEle = document.create Element("option ") ;
//myEle.value = x ;
myEle.setAttrib ute("value",x);
// myEle.text = ItemArray[x] ;
var txt = document.create TextNode(ItemAr ray[x]);
myEle.appendChi ld(txt)
// controlToPopula te.add(myEle) ;
controlToPopula te.appendChild( myEle)
}
}
}
// -->
</script>
</HEAD>
<BODY>
Hope this helps,
- Peter Schmalfeldt
<form name=form>
<table align="center">
<tr>
<td>
<select id="firstChoice " name="firstChoi ce"
onchange="selec tChange(this, form.secondChoi ce, arrItems1,
arrItemsGrp1);" >
<option value="0" selected>[SELECT]</option>
<option value="1">Land</option>
<option value="2">Sea</option>
<option value="3">Air</option>
</select>
</td><td>
<select id="secondChoic e" name="secondCho ice"
onchange="selec tChange(this, form.thirdChoic e, arrItems2,
arrItemsGrp2);" >
</select>
<select id="thirdChoice " name="thirdChoi ce">
</select>
</td>
</tr>
</table>
</form>
</BODY>
gk wrote:
i want to have 2 dpendent drown box. one for country , and the other
for city.
if you change country in box1 , the city list will also change in
box2..
How to do it in javascript ?
can you provide an example with few dumy country name and their cities.
Thank you