{"id":28118,"date":"2016-10-04T21:01:36","date_gmt":"2016-10-04T13:01:36","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=28118"},"modified":"2025-04-03T23:50:45","modified_gmt":"2025-04-03T15:50:45","slug":"search-select-using-datalist","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/","title":{"rendered":"How to Create a Datalist That&#8217;s Instantly Searchable"},"content":{"rendered":"<p>Dropdown lists are a neat way for <strong>providing options<\/strong> for an input field, particularly when the list of options available are long. A user can choose the option they want by <strong>typing into the field<\/strong>, or <strong>look through the options<\/strong> that may be a match for what they are looking for. <strong>Being able to search through the options<\/strong>, however, is the ideal solution.<\/p>\n<p>This behaviour can be achieved with the <a href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/HTML\/Element\/datalist\" target=\"_blank\" rel=\"noopener\"><code>&lt;datalist&gt;<\/code><\/a> HTML element that <strong>displays input suggestions<\/strong> for different controls, such as the <code>&lt;input&gt;<\/code> tag. However <code>&lt;datalist&gt;<\/code> only shows the available options when the user have <strong>already typed something<\/strong> into the input field.<\/p>\n<p>We can make an input field more usable if we enable users to <strong>access the full list of options<\/strong> at any time during the input taking process.<\/p>\n<p class=\"recommended_top\">\n\t\t\t\t\t<strong>Read Also:<\/strong>\u00a0\n\t\t\t\t\t<a target=\"_blank\" href=\"https:\/\/www.hongkiat.com\/blog\/html5-form-input-type\/\">Exploring HTML5 Form Input Types: Date, Color, and Range<\/a>\n\t\t\t\t<\/p>\n<p>In this post, we\u2019re going to see how to create a <strong>drop-down list that\u2019s searchable at any time<\/strong> using the <code>&lt;select&gt;<\/code> and <code>&lt;datalist&gt;<\/code> HTML elements and a little JavaScript.<\/p>\n<h3>1. Create a Datalist with Options<\/h3>\n<p>First, we create a datalist for different text editors. Make sure that the value of the <code>list<\/code> attribute of the <code>&lt;input&gt;<\/code> tag <strong>is the same as<\/strong> the <code>id<\/code> of the <code>&lt;datalist&gt;<\/code> tag \u2013 this is how we bind them to each other.<\/p>\n<pre>\r\n&lt;input type=\"text\" list=\"text_editors\"&gt;\r\n&lt;datalist id=\"text_editors\"&gt;\r\n    &lt;option value=\"Atom\"&gt;Atom\r\n    &lt;option value=\"Brackets\"&gt;Brackets\r\n    &lt;option value=\"Notepad ++\"&gt;Notepad ++\r\n    &lt;option value=\"Notepad\"&gt;Notepad\r\n    &lt;option value=\"Sublime Text\"&gt;Sublime Text\r\n    &lt;option value=\"TextEdit\"&gt;TextEdit\r\n    &lt;option value=\"TextMate\"&gt;TextMate\r\n    &lt;option value=\"Wordpad\"&gt;Wordpad\r\n&lt;\/datalist&gt;<\/pre>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/search-select-using-datalist\/datalist.jpg\" alt=\"Initial Datalist\" width=\"700\" height=\"320\"><figcaption>Initial Datalist<\/figcaption><\/figure>\n<h3>2. Make the Datalist Visible<\/h3>\n<p>By default, the <code>&lt;datalist&gt;<\/code> HTML element is <strong>hidden<\/strong>. We can only see it, when we <strong>start to type an input<\/strong> into the field the datalist is attached to.<\/p>\n<p>However there is a way to \"force\" the content of the datalist (i.e. all of its options) <strong>to appear on the webpage<\/strong>. We only need to give it a suitable <code>display<\/code> property value <strong>other than <\/strong><code><strong>none<\/strong><\/code>, for instance <code>display:block;<\/code>.<\/p>\n<pre>\r\ndatalist {\r\n    display: block;\r\n}\r\n<\/pre>\n<p>The displayed options <strong>aren\u2019t yet selectable<\/strong> at this point, the browser only <strong>renders the options<\/strong> it finds inside the datalist.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/search-select-using-datalist\/datalist-open.jpg\" alt=\"Visible Datalist\" width=\"700\" height=\"385\"><figcaption>Datalist Made Visible<\/figcaption><\/figure>\n<p>As aforementioned, due to the built-in behaviour of the <code>&lt;datalist&gt;<\/code> element, <strong>a part of the options already appear and are selectable<\/strong>, but only when the user starts to type in a string to which the browser can <strong>find a matching option<\/strong>.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/search-select-using-datalist\/datalist-open1.jpg\" alt=\"Visible Datalist with Suggestions\" width=\"700\" height=\"390\"><figcaption>Visible Datalist with Suggestions<\/figcaption><\/figure>\n<p>We also need to find a mechanism to make <em>all<\/em> options (on the above screenshot displayed under the dropdown datalist) <strong>selectable<\/strong> at <strong>any other point of the input taking process<\/strong> \u2013 when users want to check out the options before they type anything, or while they\u2019ve already taken something into the input field.<\/p>\n<h3>3. Bring in the <code>&lt;select&gt;<\/code> HTML Element<\/h3>\n<p>There are two ways to enable users to <strong>see and select all the options<\/strong> whenever they want:<\/p>\n<ol>\n<li>We can add a <strong>click event handler<\/strong> to every option, and use it to select an option when it\u2019s clicked on, or we can also <strong>transform<\/strong> the options <strong>into a real drop-down list<\/strong>, which, by default, is selectable.<\/li>\n<li>We can <strong>wrap the options<\/strong> of the datalist <strong>with the <a href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/HTML\/Element\/select\" target=\"_blank\" rel=\"noopener\"><code>&lt;select&gt;<\/code><\/a> HTML element<\/strong>.<\/li>\n<\/ol>\n<p>We\u2019ll choose the second method, as it\u2019s simpler, and it\u2019s allowed to be used <strong>as a fallback mechanism<\/strong> in browsers that don\u2019t support the <code>&lt;datalist&gt;<\/code> element. When a browser can\u2019t render & display the datalist, it <strong>renders the <code>&lt;select&gt;<\/code> element with all of its options<\/strong> instead.<\/p>\n<p>By default, the <code>select<\/code> element doesn\u2019t appear in browsers that does support datalist, that is, until we <strong>force the datalist to render its content<\/strong> with the <code>display: block;<\/code> CSS rule.<\/p>\n<p>So, when we <strong>wrap the options<\/strong> from the above example (where datalist has <code>display:block<\/code>) with the <code>&lt;select&gt;<\/code> HTML tag, the code looks like below:<\/p>\n<pre>\r\n&lt;input type=\"text\" list=\"text_editors\"&gt;\r\n&lt;datalist id=\"text_editors\"&gt;\r\n    &lt;select&gt;\r\n        &lt;option value=\"Atom\"&gt;Atom\r\n        &lt;option value=\"Brackets\"&gt;Brackets\r\n        &lt;option value=\"Notepad ++\"&gt;Notepad ++\r\n        &lt;option value=\"Notepad\"&gt;Notepad\r\n        &lt;option value=\"Sublime Text\"&gt;Sublime Text\r\n        &lt;option value=\"TextEdit\"&gt;TextEdit\r\n        &lt;option value=\"TextMate\"&gt;TextMate\r\n        &lt;option value=\"Wordpad\"&gt;Wordpad\r\n    &lt;\/select&gt;\r\n&lt;\/datalist&gt;<\/pre>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/search-select-using-datalist\/datalist-select.jpg\" alt=\"Datalist with Select\" width=\"660\" height=\"169\"><figcaption>Datalist Combined with <code>&lt;select&gt;<\/code><\/figcaption><\/figure>\n<p>To <strong>see all options<\/strong> of <code>select<\/code> in the dropdown list, we need to use the attributes <strong><code>multiple<\/code><\/strong> to show more than one options, and <strong><code>size<\/code><\/strong> for the number of options we want to show.<\/p>\n<pre>\r\n&lt;select multiple size=8&gt;\r\n<\/pre>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/search-select-using-datalist\/datalist-select-open.jpg\" alt=\"Select with the Multiple Attribute\" width=\"700\" height=\"343\"><figcaption>Adding the <code>multiple<\/code> attribute to the <code>&lt;select&gt;<\/code> tag<\/figcaption><\/figure>\n<h3>4. Add a Toggle Button<\/h3>\n<p>The full drop-down list is supposed to appear <strong>only<\/strong> when the user <strong>clicks a toggle button<\/strong> next to the input field, while the user types the working datalist is shown. Let\u2019s <strong>change the <code>display<\/code> value of the datalist<\/strong> to <code>none<\/code>, and also <strong>add a button<\/strong> next to the input field, which will toggle the <code>display<\/code> value of the datalist, and consequently trigger the appearance of <code>select<\/code>.<\/p>\n<pre>\r\ndatalist {\r\n\tdisplay: none;\r\n}\r\n<\/pre>\n<p>We also need to add the following button above the datalist in the HTML file:<\/p>\n<pre>\r\n&lt;button&gt;\u25bc&lt;\/button&gt;\r\n<\/pre>\n<p>Now let\u2019s see the JavaScript. First, we define the <strong>initial variables<\/strong>.<\/p>\n<pre>\r\nbutton = document.querySelector('button');\r\ndatalist = document.querySelector('datalist');\r\nselect = document.querySelector('select');\r\noptions = select.options;<\/pre>\n<p>Next, we need to <strong>add an event listener<\/strong> (<code>toggle_ddl<\/code>) to the click event of the button which will <strong>toggle the appearance of the datalist<\/strong>.<\/p>\n<pre>\r\nbutton.addEventListener('click', toggle_ddl);\r\n<\/pre>\n<p>Then, we define the <code>toggle_ddl()<\/code> function. To do so, we need to <strong>check the value of the <code>datalist.style.display<\/code> property<\/strong>. If it\u2019s an empty string, the datalist is hidden, so we need to <strong>set its value to <code>block<\/code><\/strong>, and also to <strong>change the button<\/strong> from a down pointing arrow to an arrow pointing up.<\/p>\n<pre>\r\nfunction toggle_ddl(){\r\n    \/* if DDL is hidden *\/\r\n    if(datalist.style.display === ''){\r\n        \/* show DDL *\/\r\n        datalist.style.display = 'block';\r\n        this.textContent=\"\u25b2\";\r\n    }\r\n    else hide_select();\r\n}\r\nfunction hide_select(){\r\n    \/* hide DDL *\/\r\n    datalist.style.display = '';\r\n    button.textContent=\"\u25bc\";\r\n}\r\n<\/pre>\n<p>The <code>hide_select()<\/code> function <strong>hides the datalist<\/strong> by setting the <code>datalist.style.display<\/code> property back to an empty string, and changing the button arrow back to point downwards.<\/p>\n<p>In the final setup, if the input fields hold a previously selected option and the drop-down list has also been triggered by a later button click, the previoulsy selected option also <strong>needs to be shown as selected<\/strong> in the drop-down list.<\/p>\n<p>So, let\u2019s add the following highlighted code to the <code>toggle_ddl()<\/code> function:<\/p>\n<pre>\r\nfunction toggle_ddl(){\r\n    \/* if DDL is hidden *\/\r\n    if(datalist.style.display === ''){\r\n        \/* show DDL *\/\r\n        datalist.style.display = 'block';\r\n        this.textContent=\"\u25b2\";\r\n        var val  = input.value;\r\n        for(var i=0; i&lt;options.length; i++) {\r\n            if ( options[i].text === val ) {\r\n                select.selectedIndex = i; break;\r\n            }\r\n        }\r\n    }\r\n    else hide_select();\r\n}\r\nfunction hide_select(){\r\n    \/* hide DDL *\/\r\n    datalist.style.display = '';\r\n    button.textContent=\"\u25bc\";\r\n}\r\n<\/pre>\n<p>We also want to hide the drop-down list when the user is typing into the input field (at the time the working datalist will appear).<\/p>\n<pre>\r\n\/* when the user wants to type into text field, hide DDL *\/\r\ninput = document.querySelector('input');\r\ninput.addEventListener('focus', hide_select);\r\n<\/pre>\n<h3>5. Update Input when an Option is Selected<\/h3>\n<p>Finally, let\u2019s <strong>add a <code>change<\/code> event handler<\/strong> to the <code>&lt;select&gt;<\/code> tag, so that when the user selects an option from the drop-down list, its value will be displayed inside the <code>&lt;input&gt;<\/code> field as well.<\/p>\n<pre>\r\n\/* when user selects an option from DDL, write it to text field *\/\r\nselect.addEventListener('change',fill_input);\r\nfunction fill_input(){\r\n    input.value = options[this.selectedIndex].value;\r\n    hide_select();\r\n}\r\n<\/pre>\n<h3>Drawbacks<\/h3>\n<p>The main drawback of this technique is the <strong>absence of a direct way to style the <code>&lt;datalist&gt;<\/code> element<\/strong> with CSS (the appearance of the <code>&lt;datalist&gt;<\/code> and <code>&lt;select&gt;<\/code> tags vary across different browsers).<\/p>\n<p>Also, in Firefox, the input text is matched against options that <em>contains<\/em> the input characters, while other browsers match options that <em>begin with<\/em> those characters. The <a href=\"https:\/\/www.w3.org\/TR\/html5\/forms.html#the-datalist-element\" target=\"_blank\" rel=\"noopener nofollow\">W3C spec<\/a> for datalist doesn\u2019t explicitly specify how the matching should be done.<\/p>\n<p>Other than that, this method is good and <strong>works in all major browsers<\/strong>, whereas in browsers where it may not work, users can still see the drop-down list, only the suggestions won\u2019t appear.<\/p>\n<p>Check out the final demo with a bit of CSS styling below:<\/p>\n<p><iframe height=\"421\" scrolling=\"no\" src=\"https:\/\/codepen.io\/\/rpsthecoder\/embed\/yJvRPE\/?height=421&theme-id=12825&default-tab=result&embed-version=2\" frameborder=\"no\" allowtransparency=\"true\" allowfullscreen=\"true\" style=\"width: 100%;\">See the Pen <a href=\"https:\/\/codepen.io\/\/rpsthecoder\/pen\/yJvRPE\/\" rel=\"nofollow\">Drop-Down list search using Datalist<\/a> by Preethi (<a href=\"https:\/\/codepen.io\/\/rpsthecoder\" rel=\"nofollow\">@rpsthecoder<\/a>) on <a href=\"https:\/\/codepen.io\/\" rel=\"nofollow\">CodePen<\/a>. <\/iframe><\/p>","protected":false},"excerpt":{"rendered":"<p>Dropdown lists are a neat way for providing options for an input field, particularly when the list of options available are long. A user can choose the option they want by typing into the field, or look through the options that may be a match for what they are looking for. Being able to search&hellip;<\/p>\n","protected":false},"author":145,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3392],"tags":[511],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.6) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Create a Datalist That&#039;s Instantly Searchable - Hongkiat<\/title>\n<meta name=\"description\" content=\"Dropdown lists are a neat way for providing options for an input field, particularly when the list of options available are long. A user can choose the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create a Datalist That&#039;s Instantly Searchable\" \/>\n<meta property=\"og:description\" content=\"Dropdown lists are a neat way for providing options for an input field, particularly when the list of options available are long. A user can choose the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2016-10-04T13:01:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-03T15:50:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/assets.hongkiat.com\/uploads\/search-select-using-datalist\/datalist.jpg\" \/>\n<meta name=\"author\" content=\"Preethi Ranjit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Preethi Ranjit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/search-select-using-datalist\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/search-select-using-datalist\\\/\"},\"author\":{\"name\":\"Preethi Ranjit\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\"},\"headline\":\"How to Create a Datalist That&#8217;s Instantly Searchable\",\"datePublished\":\"2016-10-04T13:01:36+00:00\",\"dateModified\":\"2025-04-03T15:50:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/search-select-using-datalist\\\/\"},\"wordCount\":1055,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/search-select-using-datalist\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/search-select-using-datalist\\\/datalist.jpg\",\"keywords\":[\"Web Developers\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/search-select-using-datalist\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/search-select-using-datalist\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/search-select-using-datalist\\\/\",\"name\":\"How to Create a Datalist That's Instantly Searchable - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/search-select-using-datalist\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/search-select-using-datalist\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/search-select-using-datalist\\\/datalist.jpg\",\"datePublished\":\"2016-10-04T13:01:36+00:00\",\"dateModified\":\"2025-04-03T15:50:45+00:00\",\"description\":\"Dropdown lists are a neat way for providing options for an input field, particularly when the list of options available are long. A user can choose the\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/search-select-using-datalist\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/search-select-using-datalist\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/search-select-using-datalist\\\/#primaryimage\",\"url\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/search-select-using-datalist\\\/datalist.jpg\",\"contentUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/search-select-using-datalist\\\/datalist.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/search-select-using-datalist\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create a Datalist That&#8217;s Instantly Searchable\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\",\"name\":\"Preethi Ranjit\",\"description\":\"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/preethi\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Create a Datalist That's Instantly Searchable - Hongkiat","description":"Dropdown lists are a neat way for providing options for an input field, particularly when the list of options available are long. A user can choose the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/","og_locale":"en_US","og_type":"article","og_title":"How to Create a Datalist That's Instantly Searchable","og_description":"Dropdown lists are a neat way for providing options for an input field, particularly when the list of options available are long. A user can choose the","og_url":"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2016-10-04T13:01:36+00:00","article_modified_time":"2025-04-03T15:50:45+00:00","og_image":[{"url":"https:\/\/assets.hongkiat.com\/uploads\/search-select-using-datalist\/datalist.jpg","type":"","width":"","height":""}],"author":"Preethi Ranjit","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Preethi Ranjit","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/"},"author":{"name":"Preethi Ranjit","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3"},"headline":"How to Create a Datalist That&#8217;s Instantly Searchable","datePublished":"2016-10-04T13:01:36+00:00","dateModified":"2025-04-03T15:50:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/"},"wordCount":1055,"commentCount":1,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/search-select-using-datalist\/datalist.jpg","keywords":["Web Developers"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/","url":"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/","name":"How to Create a Datalist That's Instantly Searchable - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/#primaryimage"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/search-select-using-datalist\/datalist.jpg","datePublished":"2016-10-04T13:01:36+00:00","dateModified":"2025-04-03T15:50:45+00:00","description":"Dropdown lists are a neat way for providing options for an input field, particularly when the list of options available are long. A user can choose the","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/#primaryimage","url":"https:\/\/assets.hongkiat.com\/uploads\/search-select-using-datalist\/datalist.jpg","contentUrl":"https:\/\/assets.hongkiat.com\/uploads\/search-select-using-datalist\/datalist.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/search-select-using-datalist\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create a Datalist That&#8217;s Instantly Searchable"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3","name":"Preethi Ranjit","description":"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.","url":"https:\/\/www.hongkiat.com\/blog\/author\/preethi\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-7jw","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/28118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/145"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=28118"}],"version-history":[{"count":3,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/28118\/revisions"}],"predecessor-version":[{"id":73473,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/28118\/revisions\/73473"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=28118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=28118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=28118"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=28118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}