Vikrant's avatar

dependent dropdown does not work

error :

jquery-1.12.4.js:10254 GET http://localhost/getStateList/12 404 (Not Found)

here my controller :

 public function register()
 {
        $country = DB::table("countries")->pluck("c_name","id");
        return view('Recruiter.RecruiterRegistration',compact('country'));
 }

  public function getStateList($id)
        {
        $state = DB::table("states")->where("country_id",$id)->pluck("s_name","id");
         return json_encode($state);
        }

 public function getCityList($id)
 {
     $cities = DB::table("cities")->where("state_id",$id)->pluck("ci_name","id");
     return json_encode($cities);
    }



here my view :

 <div class="row">
     <label class="control-label col-sm-2" for="pwd">City:<span style="color:Red">*</span>  </label>
        <div class="col-sm-4">          
        <!-- <input type="text" class="form-control" id="city" placeholder="Enter City"         name="city"> -->
            <select id="city" name="city" class="form-control">
                        <option value="">select</option>
                       
                    </select>
        </div>
     <label class="control-label col-sm-2" for="pwd">State:<span style="color:Red">*</span></label>
            <div class="col-sm-4">          
        <!-- <input type="text" class="form-control" id="state" placeholder="Enter State" name="state"> -->
                <select id="state" name="state" class="form-control">
                        <option value="">select</option>
                        
                    </select>
        </div>
        </div>
            <div class="row">

      <label for="country" class="col-sm-2 control-label">Country:<span style="color:Red">* </span></label>
         <div class="col-sm-4">          
             <!-- <input type="text" class="form-control" id="country" placeholder="Enter Country" name="country"> -->
                 <select id="country" name="country" class="form-control">
                        <option>select</option>
                        @foreach($country as $key => $value)
                        <option value="{{$key}}">{{$value}}</option>
                        @endforeach
                    </select>
        </div>

here my route :

    Route::get('registration','RecruiterController@register');
    Route::get('getStateList/{id}','RecruiterController@getStateList');
    Route::get('getCityList/{id}','RecruiterController@getCityList');
0 likes
0 replies

Please or to participate in this conversation.