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

108
Vistas
i want two make compare in foreach loop to compare if value of branch from jquery equal to value from foreach then selected it

I have a select and get value from jquery and want to compare it with value in foreach if two value id is similar then active the selected value how can I do this is the foreach in blade:

I want two make a comparison in foreach loop to compare if the value of branch from jquery equal to value from foreach then selected it

<select name="branch">
    @foreach($branchs as $branch)
        <option value="{{$branch->id}}">{{$branch->title}}</option>                                              
    @endforeach
</select>
 $.ajax({
        url:getHref,
        data:{id:id},
        }).done(function(data) {
            $.each(data, function(index,employee){
                $( "input[name*='name']" ).val(employee.name );
                $( "select[name='branch']").val(employee.branch_id);
                $( "select[name='role_id']" ).val(employee.role_id);
            });
        });
    });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You don't have to hard coded it since jquery will do the job for you as you changed the value of select elemnt using jquery then if the value of employee.branch_id meet the value of any option element then it will automatically selected

     $( "select[name='branch']").val(employee.branch_id);

and if you want to trigger change event

 $( "select[name='branch']").val(employee.branch_id).change();
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