Ajax for onChange of select box with Laravel (change with multiple source object like textbox1, textbox2, ....)?

yuomtheara posted 3 years ago

Any example for ajax of onChnage of select box that change multiple source object like textbox1, textbox2....?

extjac replied 3 years ago

this is how i do it


	public function getPositions($id)
		if (Request::ajax())
			$positions = DB::table('sports_positions')->select('position_id','name')->where('sport_id', '=', $id)->get();
			return Response::json( $positions );


  /* Load positions into postion <selec> */
  $( "#sport_id" ).change(function() 
    $.getJSON("/sport/"+ $(this).val() +"/positions", function(jsonData){
        select = '<select name="position" class="form-control input-sm " required id="position" >';
          $.each(jsonData, function(i,data)
               select +='<option value="'+data.position_id+'">''</option>';
        select += '</select>';
yfly replied 3 years ago

Thanks you so much @extjac , Your sample help me a lot for select option content with ajax. :)

rodvan replied 2 years ago

Thank you also! This is a really good example!

savanihd replied 9 months ago

You can also follow bellow good example link :

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us