- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
ImplementJavaScript Auto Complete / Suggestion feature
To implement JavaScript Auto Complete / Suggestion feature, the code is as follows −
Example
<!DOCTYPE html> <html> <head> <style> body{ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } </style> </head> <body> <h1>JavaScript Auto Complete / Suggestion feature</h1> <input type="text" list="datalist" class="fruits" /> <datalist id="datalist"> <option value="orange"></option> <option value="apple"></option> <option value="pineapple"></option> <option value="guava"></option> <option value="mango"></option> <option value="peach"></option> <option value="pomegranate"></option> <option value="litchi"></option> </datalist> <script type="text/javascript"> var tags = ["orange", "apple","pineapple","guava","mango","pomegranate","litchi",]; let check; document.querySelector(".fruits").addEventListener("keyup", (event) => { let value = event.target.value; document.getElementById("datalist").innerHTML = ""; tags.forEach((item) => { if (item.toLowerCase().indexOf(value.toLowerCase()) > -1) { var opt = document.createElement("option"); var sel = document.createTextNode(item); opt.appendChild(sel); document.getElementById("datalist").appendChild(opt); } }); }); </script> </body> </html>
Output
On typing something in the input field −
- Related Articles
- Auto-complete feature using Trie
- How can I write a form that assists my browser's auto-complete feature?
- What is auto refresh feature in JSP?
- Using Auto Documentation feature in SAP HANA Modeler Perspective
- How to set Adapter to Auto Complete Text view?
- How to auto-generate a step definition to a feature file in Cucumber?
- How can we implement auto-complete JComboBox in Java?\n
- Autocomplete and suggestion in ReactJS
- Get similar words suggestion using Enchant in Python
- New feature of C++17
- New feature from freecharge on whatsapp
- Explain a Feature file in SpecFlow.
- CSS overflow: auto
- Difference between Auto-fit vs Auto-fill property in CSS grid
- Write the adaptional feature of an elephant.

Advertisements