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

101
Views
Actualice dinámicamente las opciones en el campo de selección según los datos de otro campo de selección de otro formulario

¿Es posible? ¿Si es así, entonces cómo? Por favor, pon un ejemplo, porque no lo encuentro por ningún lado. (Encontré el ejemplo de opciones de actualización dinámica dependiendo de los datos de otro campo seleccionado pero en la misma forma).

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede agregar un detector de eventos al cambio de la selección y, en función del cambio de valor, cualquier otro elemento.

 const select1 = document.querySelector('.select_1'); const option1 = document.querySelector('.select_2 option:first-of-type'); select1.addEventListener('change', function(){ if(this.value === 'b'){ option1.textContent = 'newA'; option1.setAttribute('value','newA'); } else { option1.textContent = 'A'; option1.setAttribute('value','a'); } });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <form> <select class="select_1"> <option value="a">A</option> <option value="b">B</option> </select> </form> <form> <select class="select_2"> <option value="a">A</option> <option value="b">B</option> </select> </form>

about 4 years ago · Juan Pablo Isaza Report

0

Puedes probar esto usando JQuery:

 // Hide all options initially $('#selectChild option').attr('disabled',true); // When the user changes the Parent select (Animal Category) $(document).on('change', '#selectParent', function() { // Assign the value of the selected option to variable let category = $('#selectParent option:selected').val(); // Run through each Child select (Animal Name) option and filter based on its data-* attribute value $('#selectChild option').filter(function() { if ($(this).data('category') != category) { $(this).attr('disabled',true); } else { $(this).attr('disabled',false); } }) });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <h5> Animal Category </h5> <select id="selectParent"> <option value="">Please Select</option> <option value="mammal">Mammal</option> <option value="insect">Insect</option> </select> <br> <hr> <h5> Animal Name </h5> <select id="selectChild"> <option> Please Select </option> <option value="dog" data-category="mammal">Dog</option> <option value="cat" data-category="mammal">Cat</option> <option value="horse" data-category="mammal">Horse</option> <option value="spider" data-category="insect">Spider</option> <option value="ant" data-category="insect">Ant</option> <option value="roach" data-category="insect">Roach</option> </select>

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!