Add Item In Another Dropdownlist on selection of First Dropdownlist using Jquery
Add Item In Another Dropdownlist on selection of First Dropdownlist using Jquery
Jquery Refrence and workinf Function
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#drd1").change(function () {
var selectedVal = $(this).val();
//
alert(selectedVal);
if (selectedVal == "1") {
$("#drd2").get(0).options[$("#drd2").get(0).options.length] = new Option("Awards",
"1");
$("#drd2").get(0).options[$("#drd2").get(0).options.length] = new Option("BaseAdmin",
"2");
$("#drd2").get(0).options[$("#drd2").get(0).options.length] = new Option("RoadAdmin",
"3");
}
if (selectedVal == "2") {
$("#drd2").empty();
$("#drd2").get(0).options[$("#drd2").get(0).options.length] = new Option("Overfund",
"1");
}
if (selectedVal == "3") {
$("#drd2").empty();
$("#drd2").get(0).options[$("#drd2").get(0).options.length] = new Option("BaseReserve",
"2");
}
});
});
</script>
Dropdownlist
<div>
<asp:DropDownList ID="drd1" runat="server">
<asp:ListItem Value="0">Select
</asp:ListItem>
<asp:ListItem Value="1">Kandy
</asp:ListItem>
<asp:ListItem Value="2">Deol
</asp:ListItem>
<asp:ListItem Value="3">Delhi
</asp:ListItem>
</asp:DropDownList>
<br />
<asp:DropDownList ID="drd2" runat="server">
<asp:ListItem Value="0">Select
</asp:ListItem>
</asp:DropDownList>
</div>
Comments
Post a Comment