Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda