Click here to Skip to main content
15,037,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I built one mvc5 application with three cascading dropdown list, like country,state,city.

now what i need is if i select country dropdown list means state dropdown list wants to enable.and so far for state dropdown to city dropdown.

But by default state and city dropdown list is disabled. Thanks in Advance


here is my jquery:

JavaScript
    function OnCountryChange(e)
    {
       
        var selectedCountryId = $(e).val();
        var ddlStates = "#sname ";

$.ajax({
    
            url: '@Url.Action("LoadStateList", "Home")',
            type: 'get',
            dataType: 'json',
            contentType: 'application/json',
            cache: false,
            data: { "CountryId": selectedCountryId },
            success: function (data) {

              
                $( ddlStates).empty();
                $.each(data, function (i, foo) {

                    $(ddlStates).append(

$("<option></option>").val(foo.Value).html(foo.Text)

                    );
                   
                   
                  
                });
                
            },
            error: function (xhr, ajaxOptions, thrownError) {

            }
});
       
    }

    function OnStateChange(e) {
        var selectedStateId = $(e).val();
        var ddlStates = "#ciname";
       
        $.ajax({
            url: '@Url.Action("LoadCityList", "Home")',
            type: 'get',
            dataType: 'json',
            contentType: 'application/json',
            cache: false,
            data: { "StateId": selectedStateId },
            success: function (data) {


                $(ddlStates).empty();
                $.each(data, function (i, foo) {

                    $(ddlStates).append(

$("<option></option>").val(foo.Value).html(foo.Text)
                    );
                    
                   

                });
                
            },
            error: function (xhr, ajaxOptions, thrownError) {

            }
           
        }); 
    }
Posted
Updated 6-Mar-14 2:03am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900