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

299
Visualizações
How to get text on datalist option with pure javascript

i have datalist option and i want to get the text value and not the value, the picture below is the example, i want to get the Kuruha as the text and not the 1 value, how to get it properly ?

html code :

        <datalist id="in">
        <option value="1">Kuruha</option>
        <option value="2">Agencia</option>
        </datalist>
        <input list="in" id=int>

picture example

enter image description here

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can bind the change eventListener as usual on your input element, and then access its datalist.

Once there, you can filter it with find to extract the selected option (if any), and finally get the text tusing textContent.

document.getElementById('int').addEventListener('change', function() {
  let selectedOpt = Array.from(this.list.options).find(item => item.value == this.value);
  
  if (typeof selectedOpt == 'undefined') {
    document.getElementById('results').innerHTML = '';
  } else {
    document.getElementById('results').innerHTML = selectedOpt.textContent;
  }
});
<datalist id="in">
   <option value="1">Kuruha</option>
   <option value="2">Agencia</option>
 </datalist>
<input list="in" id="int">

<div id="results"></div>

about 4 years ago · Santiago Trujillo 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