Support the ongoing development of Laravel.io →
posted 10 years ago
Views
Last updated 1 year ago.
0

this is how i do it

controller

	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 );
		} 
	}

ajax

  /* 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+'">'+data.name+'</option>';
           });
        select += '</select>';
        $("#position").html(select);
    });
  });
Last updated 1 year ago.
0

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

Last updated 1 year ago.
0

Thank you also! This is a really good example!

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

yuomtheara yuomtheara Joined 12 Feb 2014

Moderators

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

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.