If I have a dropdownlist that looks like this:
<select class="form-control" id="FirstDDL" name="FirstDDL">
<option value="1">Option1</option>
<option value="2">Option2</option>
<option value="3">Option3</option>
</select>
And another dropdownlist that looks like this:
<select class="form-control" id="SecondDDL" name="SecondDDL">
<option value="">Select Option</option>
<optgroup label="Option1">
<option value="12">SubOption1Value1</option>
<option value="13">SubOption1Value2</option>
<option value="14">SubOption1Value3</option>
</optgroup>
<optgroup label="Option2">
<option value="49">SubOption2Value1</option>
<option value="50">SubOption2Value2</option>
<option value="51">SubOption2Value3</option>
</optgroup>
<optgroup label="Option3">
<option value="33">SubOption3Value1</option>
<option value="34">SubOption3Value2</option>
<option value="35">SubOption3Value3</option>
</optgroup>
</select>
Now, based on the selection of the first dropdownlist, I want the second dropdownlist to be filtered.
So if I select Option1
in the first dropdownlist.. then the second dropdownlist should show only the options under <optgroup label="Option1">
I have this so far:
$(document).ready(function () {
$("#FirstDDL").change(function () {
var selectedOption = $("option:selected", this);
var selectedText = selectedOption.val();
switch (selectedText) {
case 1:
// here is where I need to set the values of the second dropdownlist
}
});
});
Any help is appreciated.