Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

301
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!