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

279
Views
cómo abrir una lista de datos asociada a una entrada al hacer clic en un botón

Tengo un input type="text" vinculado a una datalist de datos y un button al lado.
Estoy tratando de abrir la lista de datos cuando se hace clic en el botón (como si se hiciera clic en el cuadro de entrada).
¿Cómo puedo lograr eso? parece que no hay una solución simple para esto, ¿debería usar algo que no sea una lista de datos para que sea más fácil y más compatible con los navegadores?

 input::-webkit-calendar-picker-indicator { display: none; }
 <input type="text" list="lst" name="input1" /> <button>open list</button><br> <input type="text" list="lst" name="input2" /> <button>open list</button> <datalist id="lst"> <option value="a"></option> <option value="b"></option> <option value="c"></option> </datalist>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 let BTN = document.querySelector('button'), List = document.querySelector('datalist'), selectBox = document.querySelector('select'), input = document.querySelector('input'), options = selectBox.options; BTN.onclick = ()=>{ if (List.style.display === '') { List.style.display = 'block'; BTN.textContent = "close list"; let val = input.value; for (let i = 0; i < options.length; i++) { if (options[i].text === val) { selectBox.selectedIndex = i; break; } } } else HideSelectBox(); } selectBox.addEventListener('change', ()=>{ input.value = options[selectBox.selectedIndex].value; HideSelectBox(); }); input.addEventListener('focus', HideSelectBox); function HideSelectBox () { List.style.display = ''; BTN.textContent = "open list"; }
 select { width: 185px; } datalist { display: none;} option { padding: 3px; } option:hover { background-color: #cccc; } input::-webkit-calendar-picker-indicator { display: none; }
 <label> <input list='lst'> </label> <button>open list</button> <datalist id="lst"> <label> <select multiple size=3> <option value="a">a <option value="b">b <option value="c">c </select> </label> </datalist>

about 4 years ago · Juan Pablo Isaza 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!