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

269
Views
Cómo mantener varios valores seleccionados del menú desplegable después del envío del formulario

Estoy tratando de mantener los valores seleccionados después del envío del formulario, cuando el usuario selecciona más de un valor, aún debe seleccionarse después de hacer clic en el botón Enviar.

 <?php $example = $_POST["name1"]; ?> <form action="" method="post"> <select id="id1" name="name1" class="selectpicker" title="Select Currencies" multiple="multiple"> <option <?php if (isset($example) && $example=="a") echo "selected";?>>A</option> <option <?php if (isset($example) && $example=="b") echo "selected";?>>B</option> <option <?php if (isset($example) && $example=="c") echo "selected";?>>C</option> </select> <button name="submit" type="submit" value="Submit">SUBMIT</button> </form> <script> $('#id1').on('change', function() { var values = $(this).val() $("#id2 option").hide() //hide all options $('#id2').selectpicker('deselectAll') //if want to remove all selcted optn if (values.length > 0) { for (var i = 0; i < values.length; i++) { //show where value is same.. $("#id2 option[value=" + values[i] + "]").show() } } else { $("#id2 option").show() //show all options } $('#id2').selectpicker('refresh'); //refresh selctpicker }); </script>
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Usar JS puro

 var options = document.getElementById('id1').options; for (let i = 0; i < options.length; i++) { console.log(options[i].value);//log the value }
O use jquery

 $("#id1 option").each(function(){ var thisOptionValue=$(this).val(); });

about 4 years ago · Santiago Trujillo 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!