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

150
Views
How to set multiple values to list value in JavaScript

I want to select 2 options into droplist that were given by the user variables. The code below can select just one variable, so what I can do to select more than one. These variables are already on my list.

<script type="text/javascript">
    $(document).ready(()=>{
       var  value1 ="<?php echo $name1; ?>";
       var  value2 ="<?php echo $name2; ?>";
         $('#select option[value="' + value1 +'"]').attr("selected", "selected");
         $('#select option[value="' + value2 + '"]').attr("selected", "selected");
       });     
 </script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simply you could use the val function in jquery

<script type="text/javascript">
   $(document).ready(()=>{
      var  value1 ="<?php echo $name1; ?>";
      var  value2 ="<?php echo $name2; ?>";
        $('#select').val([value1, value2]);
      });     
</script>
about 4 years ago · Juan Pablo Isaza Report
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!