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

181
Vistas
Get selected text in searchable dropdown using js

I want to get the selected text in searchable dropdown using javascript function. My expected output is my selected text. But in below code, always return the value as undefined. There's an another problem with this dropdown. When I click one time on the dropdown, it doesn't show the dropdown items. Always, I have to double click to see the dropdown items. My main issue is how to get the seleted text using js function. Hope your help.

document.querySelector('#get-value').addEventListener('click', ()=> {
  var elmValue = document.querySelector('#suggestions').value;
  document.querySelector('#result').innerHTML = elmValue;
})
    <datalist id="suggestions">
         <option>First Option</option>
         <option>Second Option</option>
    </datalist>
    <input class="form-control" autoComplete="on" list="suggestions" id="agentName"/>

<button id="get-value">
Get Value
</button>
<p>
Selected Value: <span id="result"></span>
</p>

Thank you.

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

0

I found a solution for this issue. I included name attribute to the input field.

 <input class="form-control" autoComplete="on" list="suggestions" id="agentName" name="agentName"/>

Then, using the line of code below, I was able to get the selected text.

var selectedValue =  $('[name="agentName"]').val();
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