Prof wrote:
I have the requirement of autoupdating the drop down lists , when a
selectin is done in another drop down box. I dont have a server through
which i can make it dynamic. I have to hard code it in the html. Can
someone suggest anything.
<form>
I'm looking for:
<select name="sel1" size="1"
onChange="pop2(this.options[this.selectedIndex].value)">
<option value="">-</option>
<option value="cars">cars</option>
<option value="accommodation">accommodation</option>
</select>
<br>
Further selection:
<select name="sel2" size="1">
<option value="">-</option>
</select>
<select name="sel3" size="1">
<option value="">-</option>
</select>
</form>
<script type="text/javascript">
var cars = new Array('Audi', 'BMW', 'Opel');
var car_colors = new Array('white', 'metallic', 'black');
var acc = new Array('Brussels', 'Antwerp', 'Ghent')
var acc_types = new Array('studio', 'house', 'villa');
var hyphen = new Array('-');
var S2 = document.forms[0].sel2;
var S3 = document.forms[0].sel3;
function pop2(c) {
while (S2.options.length) S2.options[0] = null;
while (S3.options.length) S3.options[0] = null;
if (c == '') { fill(hyphen, S2); fill(hyphen, S3) }
if (c == 'cars') { fill(cars, S2); fill(car_colors, S3) }
if (c == 'accommodation') { fill(acc, S2); fill(acc_types, S3) }
}
function fill(arr, el) {
for (var i = 0; i < arr.length; i++)
el.options[el.length] = new Option(arr[i], arr[i]);
}
</script>
Hope this helps,
--
Bart