mardi 5 septembre 2017

laravel jquery dependent dropdown

I have a simple drop down with a list of car manufacturers:

<label>Manufacturer
<select name="manufacturer" id="manufacturer" class="form-control input-sm" onchange="changeTwo(this.value)">
   </option>
   @foreach($manuf as $item)
  <option value=""></option>
  @endforeach
  </select>
  </label>

That is fine and my idea was to have a second dependent dropdown populated by the choice so I have a javascript method:

function changeTwo(id)
    {
        var url = '';
        url = url.replace(':id', id);
        $.get(url, function (data){
            $('#model').empty();
            $.each(data, function(id,description){
                $('#model').append("<option value='"+ id +"'>" +description + "</option>");
            });
       });
    }

The route includes:

public function testDropdown($id)
        {
            $model = ModelRange::orderBy('description')->where('manufacturer_id',"=",$id)->get();
            return $model;
        }

my problem is that dropdown is populated by [object].



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire