Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

441
Vistas
Laravel onchange SelectPicker generate another selectpicker

so the problem is, I have multiple selectpickers, when I choose first selectpicker's value another one appears and it should only include values according to previous id, based on relations. There is car brand and it has car models. So for example if I select "BMW", my models selectpicker should only show "BMW" models like "120", "318", "320" and etc.. How can I accomplish such task?

Code I have now:

        <div class="row" style="padding-top: 1cm">
            
            <select id="vehicleBrand" class="selectpicker form-control" data-live-search="true">
                <option data-tokens="Pasirinkite modeli" disabled selected>Pasirinkite modeli</option>
                @foreach ($vehicleBrands as $brand)
                    <option data-tokens="{{ $brand->name }}" value="{{ $brand->id }}">{{ $brand->name }}</option>
                @endforeach
              </select>  
        
        </div>
        <div id="modelDiv" class="row" style="padding-top: 1cm" hidden>
            <input type="text" name="selectedBrandId" id="selectedBrandId" value="none">
            <select id="vehicleModelSell" class="selectpicker form-control" data-live-search="true">
                @foreach ($vehicleModels->where('id','selectedId') as $model)
                    <option data-tokens="{{ $model->name }}" value="{{ $model->id }}">{{ $model->name }}</option>
                @endforeach
            </select>
        </div>

'selectedId' should be the id from first selectpicker, so I could fetch only needed results.

Edit:

Also this is what it looks like:

Image

At first there's only one selectpicker, when I choose the first one, second appears and I want it to show (fetch from database) only the desired ones, but I don't know how to pass id variable from first selectpicker's <option>. I suppose I should use ajax?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda