I have multiple dropdown lists on a registration page for a conference. Guests are supposed to select their first and second choice of afternoon activities. So, if a guest selects "Leisure time" in the First Choice dropdown menu, "Leisure Time" should be disable in the Second Choice dropdown menu.
I've gotten that part to work. If the guest selects from the First Choice menu first, the appropriate option is disable in the Second Choice menu.
However, I haven't managed to find a solution for if the guest selects from the Second Choice menu first. If that happens, they can select anything from the First Choice menu, and nothing is disabled. Here is my function:
function checkSelects(select1Id, select2Id) {
var select1 = document.getElementById(select1Id);
var select2 = document.getElementById(select2Id);
if (select1.value) {
for (var i = 0; i < select2.options.length; i++) {
var currentOption = select2.options[i];
if (select1.value === currentOption.value) {
currentOption.disabled = true;
} else {
currentOption.disabled = false;
}
}
}
}
An example of how the options for the dropdown list are set up:
<p>
Sunday - First Choice<span class="required">*</span>
</p>
<div class="dropdown">
<select id="selectOne" onchange="javascript:checkSelects('selectOne', 'selectTwo')">
<option></option>
<option name="ActivitySunday1" id="ActSun1_Leisure" value="Leisure">Leisure Time</option>
<option name="ActivitySunday1" id="ActSun1_Duck" value="Duck and Fenway Tour">Boston Duck and Fenway Tour</option>
<option name="ActivitySunday1" id="ActSun1_Revealed" value="Boston Revealed">Boston Revealed</option>
<option name="ActivitySunday1" id="ActSun1_Cambridge" value="Cambridge and Harvard Tour">Cambridge and Harvard Tour</option>
</select>
</div>
<div id="actsun1Error" class="error" style="display: none;">
Please select your Second choice of an afternoon activity for Sunday April 24th.
</div>
<p> Sunday - Second Choice<span class="required">*</span></p>
<div class="dropdown">
<select id="selectTwo" onchange="javascript:checkSelects('selectOne', 'selectTwo')">
<option></option>
<option name="ActivitySunday2" id="ActSun2_Leisure" value="Leisure">Leisure Time</option>
<option name="ActivitySunday2" id="ActSun2_Duck" value="Duck and Fenway Tour">Boston Duck and Fenway Tour</option>
<option name="ActivitySunday2" id="ActSun2_Revealed" value="Boston Revealed">Boston Revealed</option>
<option name="ActivitySunday2" id="ActSun2_Cambridge" value="Cambridge and Harvard Tour">Cambridge and Harvard Tour</option>
</select>
</div>
<div id="actsun2Error" class="error" style="display: none;">
Please select your Second choice of an afternoon activity for Sunday April 24th.
</div>
Thanks for the help!