Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

439
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!