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

196
Vistas
How to print the selected value of only one option from html drop down list menu

Hello i have this drop down list menu and i want to make a script that when i select only the last option the labels change in html. This is my code i have done until now:

<select id='type' name='type' class="form-control" onchange="loadText(this)">
  <option value="S">S</option>
  <option value="B">B</option>

  <option value="F">F</option>

</select>
<script>
  function loadText(select) {
    alert(select.options[select.valueOf(2)].text);
  }
</script>

I tried to get the value of the selected option but it wont work, before i had it

select.selectedIndex

but i want this function to work only for the last value not for all 3

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

0

<select id='type' name='type' class="form-control" onchange="loadText(this)">
    <option value="S">S</option>
    <option value="B">B</option>
    <option value="F">F</option>
</select>

<script>
    function loadText(select) {
        var select = document.getElementById('type');

        var lastValue = select.options[select.options.length - 1].value;
        var selectedValue = select.options[select.selectedIndex].text;

        if (lastValue === selectedValue) {
            alert(selectedValue);
        }
    }
</script>
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