0

I have two dropdownlists: One is a list of countries, and the other is a list of states that will fill if either Canada or United States is called. I'm new to asp.net and Javascript, and would like someone to point in the right direction on what I am doing wrong. I'm just trying to set my ddl to the text at the moment to see how it works, and afterwards would like to fill the ddl with the lists in the javascript code. Thank you in advance!

    <script>
        function displayStateDDL() {
            var ControlName = document.getElementById(ddlCountry.id);

            if (document.getElementById("ddlCountry").value == "United States") {
                document.getElementById("ddlState").value = "State";
            } else if (document.getElementById("ddlCountry").value == "Canada") {
                document.getElementById("ddlState").value = "Province";
            }
        }
 </script>

    <asp:DropDownList ID="ddlCountry" runat="server" Width="170px" onchange="javascript: displayStateDDL();">
    </asp:DropDownList>

<asp:DropDownList ID="ddlState" runat="server" Width="170px">   </asp:DropDownList>
Slae
  • 335
  • 5
  • 18
  • similar question here, might have some helpful information http://stackoverflow.com/questions/35135722/country-and-state-selection-using-html-and-javascript/35136079#35136079 – jmcgriz Feb 23 '16 at 20:03
  • @jmcgriz is it possible to do this with dropdownlists verses options? – Slae Feb 23 '16 at 20:06
  • an asp:DropDownList outputs that same HTML. If you inspect the HTML that's being created by your code, you should see a select element with option children – jmcgriz Feb 23 '16 at 21:27

0 Answers0