Untitled
raw download clone
TEXT
views 31
,
size 1364 b
$(document).ready(function(){
     var indstate=['MP','UP',];

     var usstate=["Texas","California",];

     var city={
         "MP":["bhopal","pune","nagpur"],
         "UP":["Agra","Nodia","Ghaziabad"],
         "Texas":["Dallas","Houston"],
         "California":["Los Angles","San francisco"]
     };


     var smap={0:indstate,1:usstate};

    $('#country').change(function(e){
            var sel =$("#country option:selected").val();
            var a=smap[sel];
            console.log(a+sel);
            $('#state').empty();
            $('#city').empty();
            $('div').empty();

            a.forEach(item=>{   
                $("#state").append($('<option></option>').val(item).html(item));

            });



    });

    $('#state').change(function(e){
        var sel =$("#state option:selected").val();
        var a=city[sel];
        console.log(a+sel);
        $('#city').empty();
        $('div').empty();

        a.forEach(item=>{   
            $("#city").append($('<option></option>').val(item).html(item));

        });



        });


    $("#city").change(function(e){

            var str ="<h3>"+$("#city option:selected").val()+","+$("#state option:selected").val()+","+$("#countary option:selected").val();

            $("div").html(str);

    });





});
close fullscreen
Login or Register to edit or fork this paste. It's free.