Dynamically Changing Drop Down Form
Hello,
I am trying to create a form that changes on the fly when I select from a list in a drop down feature. I have three different drop down fields that I need to change when someone fills out the form. This is for registering with a gymnastics school so an example of the drop down criteria:
Drop down 1 Drop down 2 Drop down 3
Select Class Select Day Select Time
Class 1 Monday Time1
Class 2 Tuesday Time2
Class 3 Wednesday Time3
Thursday Time4
Friday
Saturday
Sunday
So when the customer fills out the form, I would like for them to select from one of the classes, then based on the class they select, it brings up the days that are available for that class, then based on the day they select, they can select the time that is available for those classes on that specific day.
I was able to achieve the first half of this by selecting the class and then the day did change on the fly, but I can't figure out how to get that third drop down to select the times.
Below is the code that I have so far:
<!doctype html>
<html>
<head>
<script type="text/javascript">
function populate(s1,s2){
var s1 = document.getElementById(s1);
var s2 = document.getElementById(s2);
s2.innerHTML="";
if(s1.value == "PreSchoolJuniorGym"){
var optionArray = ["|","monday|Monday","tuesday|Tuesday","wednesday|Wednesday","thursday|Thursday","friday|Friday","saturday|Saturday","sunday|Sunday"];
}else if(s1.value == "Girls Recreational"){
var optionArray = ["|","monday|Monday","tuesday|Tuesday","wednesday|Wednesday","thursday|Thursday","saturday|Saturday","sunday|Sunday"];
}else if(s1.value == "Boys Recreational"){
var optionArray = ["|","monday|Monday","wednesday|Wednesday","saturday|Saturday"];
}
for(var option in optionArray){
var pair = optionArray[option].split("|");
var newOption = document.createElement("option");
newOption.value = pair[0];
newOption.innerHTML = pair[1];
s2.options.add(newOption);
}
}
</script>
</head>
<body>
Select Class:
<select id="select1" name="select1" onchange="populate('select1','select2')">
<option value=""></option>
<option value="PreSchoolJuniorGym">PreSchoolJuniorGym</option>
<option value="Girls Recreational">Girls Recreational</option>
<option value="Boys Recreational">Boys Recreational</option>
</select>
<hr/>
Select Class Day:
<select id="select2" name="select2">
</select>
<hr/>
Select Class Time:
<select id="select3" name="select3>
</select>
<hr/>
</body>
</html>
