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

154
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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