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

150
Visualizações
i cant perform auto selected on the select option when data retrieve from the cookie directly after refresh using jquery

This is my code working on getting the cookie data and set into a variable json_str and data retrieve from cookie was fine as refer in this image

But then the jquery statement some how cant be function as expected.

<script>    
        var json_str = getCookie('s8RelatedDepartment');
            const myArray = json_str.split(",");
            if(myArray.includes("volvo")){
                $('select[name=cars] option[value=volvo]').attr('selected','selected');
            }
            if(myArray.includes("opel")){
                $('select[name=cars] option[value=opel]').attr('selected','selected');
            }
            if(myArray.includes("saab")){
                $('select[name=cars] option[value=saab]').attr('selected','selected');
            }
            if(myArray.includes("audi")){
                $('select[name=cars] option[value=audi]').attr('selected','selected');
            }
    </script>
    
    <select name="cars" class="cars" id="cars" style="width:40%" multiple onclick="test()">
        <option value="volvo">volvo</option>
        <option value="opel">Opel</option>
        <option value="saab">Saab</option>
        <option value="audi">Audi</option>
    </select>

The select option will not selected automatically after refresh. Any ideal?

about 4 years ago · Juan Pablo Isaza
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