Currently, I am streamlining an HTML web form by using scripts to populate select box options. While the show/hide functionality works perfectly for one select with hardcoded options, it fails for a dropdown filled via script and JSON data. Can anyone pinpoint where I might be going wrong?
If "member + 1 guest" is selected, one div displays correctly. However, the other dropdown never triggers the display of the second div!
Check out the HTML snippet below:
<div id="tickets">
<label for="group1">Number of Tickets: <span class="req">*</span></label>
<select class="group1_dropdown" id="group1" name="group1">
<option value="0">-- Please select --</option>
<option value="1">Member</option>
<option value="2">Member + 1 Guest</option>
<option value="3">Member + 2 Guests</option>
<option value="4">Member + 3 Guests</option>
</select>
<label class="visuallyhidden">Year</label>
<select id="yearSelectionBox2" class="stringInfoSpacing">
<option value="0" selected="selected">Year</option>
</select>
</div>
<div id="payMethod">
<div class="header"> PAYMENT METHOD </div>
<div id="payOptions">
<div id="payInfo">
<div id="pay0" class="paymentinfo">
<p>PAYMENT INFO OPTION 1</p>
</div>
</div>
</div>
</div>
<div id="pay222" class="tacos">
<p>Years Data</p>
</div>
Below are the scripts being utilized:
var YearListItems2= "";
for (var i = 0; i < modelYearJsonList2.modelYearTable2.length; i++){
YearListItems2+= "<option value='" + modelYearJsonList2.modelYearTable2[i].modelYearID + "'>" + modelYearJsonList2.modelYearTable2[i].modelYear + "</option>";
};
$("#yearSelectionBox2").html(YearListItems2);
//The div is not showing/hiding as it should
$("#yearSelectionBox2").change(function () {
var str = "";
str = parseInt($("select option:selected").val());
if(str == 2013)
$("#pay222").show('slow');
else
$("#pay222").hide('fast');
});
//This one works as it should
$("#group1").change(function () {
var str = "";
str = parseInt($("select option:selected").val());
if(str == 2)
$("#payMethod").show('slow');
else
$("#payMethod").hide('fast');
});