Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Autocomplete select Event</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script> <style> #log{margin-top:10px;font-family:monospace;background:#f5f5f5;border:1px solid #ddd;padding:8px;} </style> </head> <body> <p>Language: <input type="text" id="lang"></p> <div id="log">No selection yet.</div> <script> var languages = ["JavaScript", "PHP", "Python", "Java", "C++"]; $(function(){ $("#lang").autocomplete({ source: languages, select: function(e, ui){ $("#log").text("Chosen: " + ui.item.value); } }); }); </script> </body> </html>
Output