district based on state ajax call while adding and editing in laravel code example

Example: district based on state ajax call while adding and editing in laravel

<!DOCTYPE html><html><head>    <title>Dependent country state city dropdown using ajax in PHP Laravel Framework</title>    <link rel="stylesheet" href="http://www.expertphp.in/css/bootstrap.css">        <script src="http://demo.expertphp.in/js/jquery.js"></script></head><body><div class="container">    <div class="panel panel-default">      <div class="panel-heading">Dependent country state city dropdown using ajax in PHP Laravel Framework</div>      <div class="panel-body">            <div class="form-group">                <label for="title">Select Country:</label>                {!! Form::select('country', ['' => 'Select'] +$countries,'',array('class'=>'form-control','id'=>'country','style'=>'width:350px;'));!!}                           </div>            <div class="form-group">                <label for="title">Select State:</label>                <select name="state" id="state" class="form-control" style="width:350px">                </select>            </div>                     <div class="form-group">                <label for="title">Select City:</label>                <select name="city" id="city" class="form-control" style="width:350px">                </select>            </div>      </div>    </div></div><script type="text/javascript">    $('#country').change(function(){    var countryID = $(this).val();        if(countryID){        $.ajax({           type:"GET",           url:"{{url('api/get-state-list')}}?country_id="+countryID,           success:function(res){                           if(res){                $("#state").empty();                $("#state").append('<option>Select</option>');                $.each(res,function(key,value){                    $("#state").append('<option value="'+key+'">'+value+'</option>');                });                       }else{               $("#state").empty();            }           }        });    }else{        $("#state").empty();        $("#city").empty();    }         });    $('#state').on('change',function(){    var stateID = $(this).val();        if(stateID){        $.ajax({           type:"GET",           url:"{{url('api/get-city-list')}}?state_id="+stateID,           success:function(res){                           if(res){                $("#city").empty();                $.each(res,function(key,value){                    $("#city").append('<option value="'+key+'">'+value+'</option>');                });                       }else{               $("#city").empty();            }           }        });    }else{        $("#city").empty();    }           });</script></body></html>

Tags:

Misc Example