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

151
Views
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
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!