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

156
Views
set selected value in dropdown when update data in laravel using ajax

I have dropdown like this:

                <div class="row">
                    <div class="col-md-12 col-sm-6">
                        <div class="form-group">
                            <label for="">{{ __('Product Plan') }}<span class="required"></span></label>

                            <select name="product_plan" class="form-control" id="product_plan" style="width: 50%">
                                @foreach ($product_plan as $val)
                                    <option value="{{ $val->productplanID }}">
                                        {{ $val->productplanID }}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                </div>

I using modal to update this data, so I use AJAX. This is my ajax method for get the data:

$('body').on('click', '.editPlanSchedule', function() {
var Item_id = $(this).data('id');
$.get("/quotation/getEditPlanSchedule" + '/' + Item_id, function(data) {
    $('#product_plan').val(data.product_plan);
    // console.log(data.product_plan);
})

});

I get the data correctly. My question is, how to put the selected value in select option from database using ajax? I try console.log(data.product_plan), I get the data. But when I do $('#product_plan').val(data.product_plan);, select option not selected the correct select from database.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this:

$('body').on('click', '.editPlanSchedule', function() {
var Item_id = $(this).data('id');
$.get("/quotation/getEditPlanSchedule" + '/' + Item_id, function(data) {
    let options = "";
    data.product_plan.forEach(p => {
        options += `<option value="${p.productplanID}">${p.productplanID}</option>`;
    }
    $('#product_plan').val(options);
})
});
about 4 years ago · Juan Pablo Isaza Report
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!