I have two drop down list shown below second drop down list contains 8 items and first drop down list contains 3 elements based on first dropdown list i have to display particular items in second dropdown list
ex: first dropdown list i will select "pass" then automatically second dropdown list shows only 3 items(out of 8) and if i select "Fail" or "Retake" then it should show remaining 5 items.
html code :
<td valign="middle" style="font-size: 0.9em" id="attemptstatus">@Html.DropDownListFor(model => model.CTData[i][0].AttemptStatus, new SelectList(
new List<Object>{
new { value = 0 , text = "Select" },
new { value = 1 , text = "Pass" },
new { value = 2 , text = "Fail" },
new { value = 3 , text = "Retake"}
},
"value",
"text",
statusvalue), new { @class = "attemptstatus", @id = "attempttestid" + i }) </td>
<td id="ctpassoption" style="width: 400px">@Html.DropDownListFor(model => model.CTData[i][0].RemarkId1, new SelectList(Model.PassOptions, "Value", "Text", Model.CTData[i][0].RemarkId1), new { @class = "ct_option", @id = "passid" + i })</td>
javascript code :
if (($('#attempttestid0').val() === '2') || ($('#attempttestid0').val() === '3'))
{
var a="@ViewBag.TempPass"
var arr=a.split(",");
for(var i=0;i<arr.length;i++)
{
$("#passid0 option[value=" + arr[i] + "]").disable();
}
}
else {
var a1="@ViewBag.TempOther"
var arr1=a1.split(",");
for(var i=0;i<arr1.length;i++)
{
$("#passid0 option[value=" + arr1[i] + "]").disable();
}
}
$('#attempttestid0').on('change', function () {
if ((this.value === '2')||(this.value === '3')) {
var a2="@ViewBag.TempPass"
var arr2=a2.split(",");
for(var i=0;i<arr2.length;i++)
{
$("#passid0 option[value=" + arr2[i] + "]").disable();
}
}
else
{
var a3="@ViewBag.TempOther"
var arr3=a3.split(",");
for(var i=0;i<arr3.length;i++)
{
$("#passid0 option[value=" + arr3[i] + "]").disable();
}
}
});