Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
Toggle Button text After Selecting Option HTML

So, I've been trying to toggle a button text after selection an certain option.

However no matter what I try the button text doesn't change.

I have this HTML code:

<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>

And this is the JS code:

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;
}

It was supposed to toggle the text "Convert" to "Convert to Fº" / "Convert to Kº" on the user selection of Farenheit or Kelvin.

Could someone help me, please?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Put the switch code into an event listener, that listens for a change in the dropdown.

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda