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
Display a different default value after selected an option

What I want to achieve is after a user selects an option, the input would then display "select another option" instead of display the value name of the selected option.

Basic example:

<select>
<option value="" selected>Select an Option</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Attach a change event listener to the select that checks whether this is the first time the user selected an option. If it is, you can set the value to "" and set the textContent of the selected option to "Select another option."

const select = document.querySelector('select');
var isFirst = true;
select.addEventListener('change', function() {
  if (isFirst) {
    select.value = "";
    select.options[select.selectedIndex].textContent = "select another option";
    isFirst = false
  }
})
<select>
  <option value="" selected>Select an Option</option>
  <option value="1">One</option>
  <option value="2">Two</option>
</select>

If you want to do it everytime the user selects an option:

const select = document.querySelector('select');
select.addEventListener('change', function() {
  select.value = "";
  select.options[select.selectedIndex].textContent = "select another option";
})
<select>
  <option value="" selected>Select an Option</option>
  <option value="1">One</option>
  <option value="2">Two</option>
</select>

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