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

161
Views
Alternar el texto del botón después de seleccionar la opción HTML

Entonces, he estado tratando de alternar el texto de un botón después de seleccionar una determinada opción.

Sin embargo, no importa lo que intente, el texto del botón no cambia.

Tengo este código HTML:

 <select id="temp"> <option value="selectOption" disabled selected>Select</option> <option value="farenheit">Farenheit</option> <option value="kelvin">Kelvin</option> </select><br> <button id="buttonTemp" onclick="converterTemp()">Convert</button><br>

Y este es el código JS:

 const slt = document.querySelector('select'); switch (slt.value) { case 'farenheit': document.getElementById('buttonTemp').innerHTML = 'Convert to Fº'; break; case 'kelvin': document.getElementById('buttonTemp').innerHTML = 'Convert to kº'; break; }

Se suponía que debía alternar el texto "Convertir" a "Convertir a Fº" / "Convertir a Kº" en la selección del usuario de Farenheit o Kelvin.

¿Podría alguien ayudarme, por favor?

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

0

Coloque el código del interruptor en un detector de eventos, que escucha un cambio en el menú desplegable.

 const slt = document.querySelector('select'); slt.addEventListener('change', () => { switch (slt.value) { case 'farenheit': document.getElementById('buttonTemp').innerHTML = 'Convert to Fº'; break; case 'kelvin': document.getElementById('buttonTemp').innerHTML = 'Convert to kº'; break; } })
 <select id="temp"> <option value="selectOption" disabled selected>Select</option> <option value="farenheit">Farenheit</option> <option value="kelvin">Kelvin</option> </select><br> <button id="buttonTemp" onclick="converterTemp()">Convert</button><br>

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!