I have an aspx Master page application where I have two dropdownlist controls in the asp:content section of the child aspx page. One of the controls is populated from SQL database. The other is populated based on the item selected from the first dropdown. I am trying to use this solution in my code, however I am getting an error:
JavaScript runtime error: Unable to get property 'forEach' of undefined or null reference
How can I get the city names to be displayed based on State selected?
My code block is:
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<script type="text/javascript">
AL = new Array('Birmingham', 'Montgomery', 'Tuscaloosa');
FL = new Array('Miami', 'FtLauderdale', 'Jacksonville');
GA = new Array('Atlanta', 'Macon', 'Athens');
populateSelect();
$(function () {
$('#ddlState').change(function () {
populateSelect();
});
});
function populateSelect() {
category = $('#ddlState').val();
$('#ddlCity').html('');
eval(category).forEach(function (t) {
$('#ddlCity').append('<option>' + t + '</option>');
});
}
</script>
<asp:DropDownList ID="ddlCity" runat="server" CssClass="stdFldWidth" onchange="setFDFlag()">
</asp:DropDownList>
<asp:DropDownList ID="ddlState" runat="server" CssClass="stdFldWidth" DataSourceID="dsUSState"
DataTextField="US_State" DataValueField="State_ID" AutoPostBack="true" >
</asp:DropDownList>
Update:
Protected Sub ddlState_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlType.SelectedIndexChanged
If ddlState.SelectedValue = "FL" Then
DisplayRegulation(FL)
End If