G
Googy
I Want to generate dynamic values in a drop down menu based on the
selection of another drop down menu. Following are my html snippet and
my javascript code.
HTML Snippet
<select name = "events" id = "events" class="fValidate['required']"
title='Select an event for which you want to register'>
<option value = "">Select an event</option>
<option value = "embryo">Embryo</option>
<option value = "combatant">Combatant</option>
<option value = "madeitmyself">Made It Myself</option>
<option value = "dawarrior">Da Warrior</option>
<option value = "dumbcharades">Isharon hi Isharon me</option>
<option value = "drishya">Drishya</option>
<option value = "raganight">Raga Night</option>
<option value = "entrapment">Entrapment</option>
<option value = "formulazero">Formula Zero</option>
<option value = "jam">Jam</option>
<option value = "goalgo">Go Algo</option>
<option value = "bootstrapping">Boot Strapping</option>
<option value = "metallica">Metallica</option>
<option value = "bguru">B-Guru</option>
<option value = "wrongturn">Wrong Turn</option>
<option value = "footloose">Foot Loose</option>
<option value = "adaa">Adaa</option>
<option value = "subito">Subito</option>
<option value = "bestsellers">Best Sellers</option>
<option value = "antakshari">Antakshari</option>
</select>
<select name = "team" id = "team" class="fValidate['required']"
title='Select the size of team'>
<option value="">Team Size</option>
</select>
Javascript code
window.onload = initForm;
function initForm() {
document.getElementById("events").selectedIndex = 0;
document.getElementById("events").onchange = populateTeamsize;
}
function populateTeamsize() {
var teamsize = new Array(1,1,5,1,5,10,3,3,3,2,2,1,2,2,1,2,8,2,2,6);
var teamStr = this.options[this.selectedIndex].value;
var index;
if (teamStr != "") {
switch(teamStr) {
case "embryo" :
index = 0;
break;
case "combatant" :
index = 1;
break;
case "madeitmyself" :
index = 2;
break;
case "dawarrior" :
index = 3;
break;
case "dumbcharades" :
index = 4;
break;
case "drishya" :
index = 5;
break;
case "raganight" :
index = 6;
break;
case "entrapment" :
index = 7;
break;
case "formulazero" :
index = 8;
break;
case "jam" :
index = 9;
break;
case "goalgo" :
index = 10;
break;
case "bootstrapping" :
index = 11;
break;
case "metallica" :
index = 12;
break;
case "bguru" :
index = 13;
break;
case "wrongturn" :
index = 14;
break;
case "foorloose" :
index = 15;
break;
case "adaa" :
index = 16;
break;
case "subito" :
index = 17;
break;
case "bestsellers" :
index = 19;
break;
case "antakshari" :
index = 20;
break;
}
document.getElementById("team").options.length = 0;
for(var i=0; i<teamsize[index]; i++) {
document.getElementById("team").options = new Option(i+1);
}
}
}
But the problem is that dymaic numbers are not generated in second
drop down menu after selecting an option from first one ...
Please help i am not getting the error in my code, if any one can
debug it please answer.
selection of another drop down menu. Following are my html snippet and
my javascript code.
HTML Snippet
<select name = "events" id = "events" class="fValidate['required']"
title='Select an event for which you want to register'>
<option value = "">Select an event</option>
<option value = "embryo">Embryo</option>
<option value = "combatant">Combatant</option>
<option value = "madeitmyself">Made It Myself</option>
<option value = "dawarrior">Da Warrior</option>
<option value = "dumbcharades">Isharon hi Isharon me</option>
<option value = "drishya">Drishya</option>
<option value = "raganight">Raga Night</option>
<option value = "entrapment">Entrapment</option>
<option value = "formulazero">Formula Zero</option>
<option value = "jam">Jam</option>
<option value = "goalgo">Go Algo</option>
<option value = "bootstrapping">Boot Strapping</option>
<option value = "metallica">Metallica</option>
<option value = "bguru">B-Guru</option>
<option value = "wrongturn">Wrong Turn</option>
<option value = "footloose">Foot Loose</option>
<option value = "adaa">Adaa</option>
<option value = "subito">Subito</option>
<option value = "bestsellers">Best Sellers</option>
<option value = "antakshari">Antakshari</option>
</select>
<select name = "team" id = "team" class="fValidate['required']"
title='Select the size of team'>
<option value="">Team Size</option>
</select>
Javascript code
window.onload = initForm;
function initForm() {
document.getElementById("events").selectedIndex = 0;
document.getElementById("events").onchange = populateTeamsize;
}
function populateTeamsize() {
var teamsize = new Array(1,1,5,1,5,10,3,3,3,2,2,1,2,2,1,2,8,2,2,6);
var teamStr = this.options[this.selectedIndex].value;
var index;
if (teamStr != "") {
switch(teamStr) {
case "embryo" :
index = 0;
break;
case "combatant" :
index = 1;
break;
case "madeitmyself" :
index = 2;
break;
case "dawarrior" :
index = 3;
break;
case "dumbcharades" :
index = 4;
break;
case "drishya" :
index = 5;
break;
case "raganight" :
index = 6;
break;
case "entrapment" :
index = 7;
break;
case "formulazero" :
index = 8;
break;
case "jam" :
index = 9;
break;
case "goalgo" :
index = 10;
break;
case "bootstrapping" :
index = 11;
break;
case "metallica" :
index = 12;
break;
case "bguru" :
index = 13;
break;
case "wrongturn" :
index = 14;
break;
case "foorloose" :
index = 15;
break;
case "adaa" :
index = 16;
break;
case "subito" :
index = 17;
break;
case "bestsellers" :
index = 19;
break;
case "antakshari" :
index = 20;
break;
}
document.getElementById("team").options.length = 0;
for(var i=0; i<teamsize[index]; i++) {
document.getElementById("team").options = new Option(i+1);
}
}
}
But the problem is that dymaic numbers are not generated in second
drop down menu after selecting an option from first one ...
Please help i am not getting the error in my code, if any one can
debug it please answer.