Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda