How can caming towns null ?

Harun Ergün 120 Reputation points

When the city is selected, it comes with the town. But when the city is selected, I want the town to be empty and for the user to select it.

User's image

I want when user choose city second drowboxlist caming null

how can add ? my code is ;

For example "AYTINTEPE" will be null after user choose towns

$('#ikametSehir').on("click", function () {
            var x = document.getElementById("ikametIlce");
            var a = $('#ikametSehir :selected').text();
A set of technologies in the .NET Framework for building web applications and XML web services.
1,323 questions
ASP.NET Web Forms
ASP.NET Web Forms
A part of the ASP.NET web application framework that can be used to create ASP.NET web applications.
462 questions
A Microsoft web application framework that implements the model-view-controller (MVC) design pattern.
736 questions
No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 11,821 Reputation points Microsoft Vendor

    Hi @Harun Ergün,

    You just need to add an initial "select" value to a DropDownList. <asp:ListItem Text="---Select---" Value="0" />

    <script src="Scripts/jquery-3.4.1.min.js"></script>
       <script type="text/javascript">       
           $(document).ready(function () {
               $("#ikametSehir").change(function () {
                   val = $("#ikametSehir option:selected").text();
                   var states = document.getElementById('ikametIlce');
            #ikametIlce.hidden { display:none; }
        <form id="form1" runat="server">
            <asp:DropDownList ID="ikametSehir" runat="server" Width="145px" ClientIDMode="Static">
                 <asp:ListItem Text="---Select---" Value="0" /> 
                <asp:ListItem Value="AF">Afghanistan</asp:ListItem>
                <asp:ListItem Value="AL">Albania</asp:ListItem>
                <asp:ListItem Value="DZ">Algeria</asp:ListItem>
                 <asp:DropDownList ID="ikametIlce" runat="server" Width="145px" class="hidden" >
                     <asp:ListItem Text="---Select---" Value="0" />   
                <asp:ListItem Value="AF">Afghanistan</asp:ListItem>
                <asp:ListItem Value="AL">Albania</asp:ListItem>
                <asp:ListItem Value="DZ">Algeria</asp:ListItem>
                <asp:ListItem Value="AS">American Samoa</asp:ListItem>


    Best regards,
    Lan Huang

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    No comments

0 additional answers

Sort by: Most helpful