{"id":5639,"date":"2020-04-28T08:19:00","date_gmt":"2020-04-28T08:19:00","guid":{"rendered":"https:\/\/webdevtrick.com\/?p=5639"},"modified":"2020-04-28T15:33:45","modified_gmt":"2020-04-28T15:33:45","slug":"html-combobox-with-javascript","status":"publish","type":"post","link":"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/","title":{"rendered":"HTML Combobox With JavaScript and CSS | Combobox Types &#038; Patterns"},"content":{"rendered":"<p><strong>How we can create a Combobox pattern using HTML CSS JS? Solution: See this HTML combo box With JavaScript and CSS, Combobox Types &amp; Patterns.<\/strong><\/p>\n<p>Previously I have shared some <span><a href=\"https:\/\/webdevtrick.com\/tag\/select\/\" target=\"_blank\" rel=\"noopener noreferrer\">select option<\/a><\/span> programs, this is also like that but it is a combo box. Basically, A <strong>combo box<\/strong> is a commonly used graphical user interface widget. Traditionally, it is a combination of a <strong>drop-down list<\/strong> or list box and<strong> options<\/strong>. This is a kind of d<strong>ropdown select option<\/strong>, which we generally use.<\/p>\n<p>Today you will learn to create C<strong>ombobox Types &amp; Patterns<\/strong> using <strong>HTML CSS and JavaScript<\/strong>. Basically, there are three types of<strong> combo box<\/strong> types of patterns. The first one is a simple <span><a href=\"https:\/\/webdevtrick.com\/tag\/dropdown\" target=\"_blank\" rel=\"noopener noreferrer\">dropdown<\/a><\/span> select <strong>options list<\/strong>, the second one is <strong>editable<\/strong>, and the third one is <strong>multi-selectable<\/strong>. The second combobox which is editable, you can remove\/add characters after a <strong>selected option<\/strong>. And the third one this <strong>multi-selectable<\/strong>, you can select <strong>multiple options<\/strong> and all the selected options will show above the box.<\/p>\n<p>So, Today I am sharing <strong>HTML Combobox With JavaScript<\/strong> and CSS. There I have used HTML and JavaScript to create the program and CSS for styling. Also, the program can <strong>detect<\/strong> some <strong>keys<\/strong> like arrow up, arrow down, backspace, etc. You can use this program on your website, you can choose any pattern or type and put on your website.<\/p>\n<p>If you are thinking now how these combo boxes actually are, then see the preview given below.<\/p>\n<h3>Preview Of Combobox Types and Patterns<\/h3>\n<p>See this video preview to getting an idea of how these <strong>combo boxes<\/strong> look like.<\/p>\n<div style=\"width: 640px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-5639-1\" width=\"640\" height=\"360\" loop autoplay preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/webdevtrick.com\/wp-content\/uploads\/html-combobox.mp4?_=1\" \/><a href=\"https:\/\/webdevtrick.com\/wp-content\/uploads\/html-combobox.mp4\">https:\/\/webdevtrick.com\/wp-content\/uploads\/html-combobox.mp4<\/a><\/video><\/div>\n<a class=\"maxbutton-2 maxbutton maxbutton-demo\" target=\"_blank\" rel=\"noopener\" href=\"https:\/\/webdevtrick.com\/demos\/html-combobox-types\/\"><span class='mb-text'>Live Demo<\/span><\/a>\n<p>Now you can see this program visually, also you can see it live by pressing the button given above. If you like this, then get the <strong>source code<\/strong> of its.<\/p>\n<p><span style=\"font-size: 14pt;\">You May Also Like:<\/span><\/p>\n<ul>\n \t<span><\/p>\n<li><a href=\"https:\/\/webdevtrick.com\/css-info-card-animation\/\" target=\"_blank\" rel=\"noopener noreferrer\">CSS Info Card Animation<\/a><\/li>\n<li><a href=\"https:\/\/webdevtrick.com\/minimal-to-do-app\/\" target=\"_blank\" rel=\"noopener noreferrer\">Minimal To Do App<\/a><\/li>\n<li><a href=\"https:\/\/webdevtrick.com\/javascript-shopping-cart\/\" target=\"_blank\" rel=\"noopener noreferrer\">JavaScript Shopping Cart<\/a><\/li>\n<li><a href=\"https:\/\/webdevtrick.com\/swappy-radio-buttons\/\" target=\"_blank\" rel=\"noopener noreferrer\">Swappy Radio Buttons<\/a><\/li>\n<p><\/span>\n<\/ul>\n<h2>HTML Combobox With JavaScript and CSS Source Code<\/h2>\n<p>Before <strong>sharing source code<\/strong>, let&#8217;s talk about it. First I have created 3 sections for <strong>3 types<\/strong> of the <strong>combo boxes<\/strong>. I have created a dedicated span to each box, and created the section using div. There I have used <strong>area-*<\/strong> commands and put values, later it will be modified by <span><a href=\"https:\/\/webdevtrick.com\/web-development\/javascript\/\" target=\"_blank\" rel=\"noopener noreferrer\"><strong> JavaScript<\/strong><\/a><\/span>. Also In the <strong>HTML file<\/strong>, I have linked other files like <strong>CSS and JavaScript<\/strong>.<\/p>\n<p>Now <strong>using CSS<\/strong> I have placed all the elements in the right place, as you can see in the preview. With CSS first I gave<strong> basic values<\/strong> like size, position, margin, padding, etc to all the elements. Also, I gave <strong>color values<\/strong> and other values which elements dynamically created using JS. And did many other things with CSS.<\/p>\n<p><strong>JavaScript<\/strong> handling here the whole functions of the program. There Js <span><a href=\"https:\/\/webdevtrick.com\/javascript-keycode-detect\/\" target=\"_blank\" rel=\"noopener noreferrer\">detecting key<\/a><\/span> and do actions using <span class=\"lang:default decode:true crayon-inline\">if() return{}<\/span> command.\u00a0 Detected all actions and movements using <span class=\"lang:default decode:true crayon-inline \">.addEventListener<\/span> command. In the <strong>JavaScript file<\/strong>, I have done many things. JS codes are little complicated, if you have good knowledge then you can understand.<\/p>\n<p>Left all other things you will understand after <strong>getting the codes<\/strong>, I can&#8217;t explain all in writing. For creating this program you have to create 3 files. First file for <strong>HTML<\/strong>, second for <strong>CSS<\/strong>, and the third file for <strong>JavaScript<\/strong>. Follow the steps to creating this without any error.<\/p>\n<p><span style=\"font-size: 14pt;\">index.html<\/span><\/p>\n<p>Create an HTML file named &#8216;<em><strong>index.html<\/strong><\/em>&#8216; and put these codes given below.<\/p>\n<pre class=\"height-set:true height:750 lang:xhtml decode:true \" title=\"index.html\">&lt;!DOCTYPE html&gt;\r\n&lt;!--Code By Webdevtrick ( https:\/\/webdevtrick.com )--&gt;\r\n&lt;html lang=\"en\" &gt;\r\n&lt;head&gt;\r\n  &lt;meta charset=\"UTF-8\"&gt;\r\n  &lt;title&gt;Combobox Patterns | Webdevtrick.com&lt;\/title&gt;\r\n  &lt;link rel=\"stylesheet\" href=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/normalize\/5.0.0\/normalize.min.css\"&gt;\r\n&lt;link rel=\"stylesheet\" href=\"style.css\"&gt;\r\n\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;label id=\"combo1-label\" class=\"combo-label\"&gt;Read-only Select&lt;\/label&gt;\r\n&lt;div class=\"combo js-select\"&gt;\r\n  &lt;div\r\n       aria-activedescendant=\"\"\r\n       aria-autocomplete=\"none\"\r\n       aria-controls=\"listbox1\"\r\n       aria-expanded=\"false\"\r\n       aria-haspopup=\"listbox\"\r\n       aria-labelledby=\"combo1-label\"\r\n       id=\"combo1\"\r\n       class=\"combo-input\"\r\n       role=\"combobox\"\r\n       tabindex=\"0\"\r\n       &gt;&lt;\/div&gt;\r\n  &lt;div class=\"combo-menu\" role=\"listbox\" id=\"listbox1\"&gt;&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;label for=\"combo2\" class=\"combo-label\"&gt;Editable Combobox&lt;\/label&gt;\r\n&lt;div class=\"combo js-combobox\"&gt;\r\n  &lt;input\r\n         aria-activedescendant=\"\"\r\n         aria-autocomplete=\"none\"\r\n         aria-controls=\"listbox2\"\r\n         aria-expanded=\"false\"\r\n         aria-haspopup=\"listbox\"\r\n         id=\"combo2\"\r\n         class=\"combo-input\"\r\n         role=\"combobox\"\r\n         type=\"text\"\r\n         \/&gt;\r\n  &lt;div class=\"combo-menu\" role=\"listbox\" id=\"listbox2\"&gt;&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;label id=\"combo3-label\" class=\"combo-label\"&gt;Multi-select Combobox&lt;\/label&gt;\r\n&lt;span id=\"combo3-remove\" style=\"display: none\"&gt;remove&lt;\/span&gt;\r\n&lt;ul class=\"selected-options\" id=\"combo3-selected\"&gt;&lt;\/ul&gt;\r\n&lt;div class=\"combo js-multiselect\"&gt;\r\n  &lt;input\r\n         aria-activedescendant=\"\"\r\n         aria-autocomplete=\"none\"\r\n         aria-controls=\"listbox3\"\r\n         aria-expanded=\"false\"\r\n         aria-haspopup=\"listbox\"\r\n         aria-labelledby=\"combo3-label combo3-selected\"\r\n         id=\"combo3\"\r\n         class=\"combo-input\"\r\n         role=\"combobox\"\r\n         type=\"text\"\r\n         \/&gt;\r\n  &lt;div class=\"combo-menu\" role=\"listbox\" id=\"listbox3\"&gt;&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;script  src=\"function.js\"&gt;&lt;\/script&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><span style=\"font-size: 14pt;\">style.css<\/span><\/p>\n<p>Now create a CSS file named &#8216;<em><strong>style.css<\/strong><\/em>&#8216; and put these codes given here.<\/p>\n<pre class=\"height-set:true height:750 lang:css decode:true \" title=\"style.css\">\/* Code By Webdevtrick ( https:\/\/webdevtrick.com ) *\/\r\n*, *::before, *::after {\r\n  box-sizing: border-box;\r\n}\r\nbody {\r\n  background-color: #f5f5f5;\r\n  font-family: \"Segoe UI\", SegoeUI, \"Helvetica Neue\", Helvetica, Arial, sans-serif;\r\n  font-size: 120%;\r\n  line-height: 1.4;\r\n  margin: 0 auto;\r\n  padding: 2em;\r\n}\r\n\r\n.combo {\r\n  display: block;\r\n  margin-bottom: 1.5em;\r\n  max-width: 400px;\r\n  position: relative;\r\n}\r\n\r\n.combo::after {\r\n  border-bottom: 2px solid rgba(0, 0, 0, 0.5);\r\n  border-right: 2px solid rgba(0, 0, 0, 0.5);\r\n  content: '';\r\n  display: block;\r\n  height: 12px;\r\n  pointer-events: none;\r\n  position: absolute;\r\n  right: 16px;\r\n  top: 50%;\r\n  transform: translate(0, -65%) rotate(45deg);\r\n  width: 12px;\r\n}\r\n\r\n.combo-input {\r\n  background-color: #f5f5f5;\r\n  border: 2px solid rgba(0, 0, 0, 0.5);\r\n  border-radius: 4px;\r\n  display: block;\r\n  font-size: 1em;\r\n  min-height: calc(1.4em + 26px);\r\n  padding: 12px 16px 14px;\r\n  text-align: left;\r\n  width: 100%;\r\n}\r\n\r\n.open .combo-input {\r\n  border-radius: 4px 4px 0 0;\r\n}\r\n\r\n.combo-input:focus {\r\n  border-color: #e60023;\r\n  box-shadow: 0 0 4px 2px #e60023;\r\n  outline: 5px solid transparent;\r\n}\r\n\r\n.combo-label {\r\n  display: block;\r\n  font-size: 20px;\r\n  font-weight: 100;\r\n  margin-bottom: 0.25em;\r\n}\r\n\r\n.combo-menu {\r\n  background-color: #f5f5f5;\r\n  border: 1px solid rgba(0, 0, 0, 0.42);\r\n  border-radius: 0 0 4px 4px;\r\n  display: none;\r\n  max-height: 300px;\r\n  overflow-y: scroll;\r\n  left: 0;\r\n  position: absolute;\r\n  top: 100%;\r\n  width: 100%;\r\n  z-index: 100;\r\n}\r\n\r\n.open .combo-menu {\r\n  display: block;\r\n}\r\n\r\n.combo-option {\r\n  padding: 10px 12px 12px;\r\n}\r\n\r\n.combo-option.option-current,\r\n.combo-option:hover {\r\n  background-color: rgba(0, 0, 0, 0.1);\r\n}\r\n\r\n.combo-option.option-selected {\r\n  padding-right: 30px;\r\n  position: relative;\r\n}\r\n\r\n.combo-option.option-selected::after {\r\n  border-bottom: 2px solid #000;\r\n  border-right: 2px solid #000;\r\n  content: '';\r\n  height: 16px;\r\n  position: absolute;\r\n  right: 15px;\r\n  top: 50%;\r\n  transform: translate(0, -50%) rotate(45deg);\r\n  width: 8px;\r\n}\r\n\r\n.selected-options {\r\n  list-style-type: none;\r\n  margin: 0;\r\n  max-width: 400px;\r\n  padding: 0;\r\n}\r\n\r\n.selected-options li {\r\n  display: inline-block;\r\n  margin-bottom: 5px;\r\n}\r\n\r\n.remove-option {\r\n  background-color: #ff3d3d;\r\n  border: 1px solid #ff3d3d;\r\n  border-radius: 3px;\r\n  color: #fff;\r\n  font-size: 0.75em;\r\n  font-weight: bold;\r\n  margin-bottom: 6px;\r\n  margin-right: 6px;\r\n  padding: 0.25em 1.75em 0.25em 0.25em;\r\n  position: relative;\r\n}\r\n\r\n.remove-option:focus {\r\n  border-color: #baa1dd;\r\n  box-shadow: 0 0 3px 1px #ff3d3d;\r\n  outline: 3px solid transparent;\r\n}\r\n\r\n.remove-option::before,\r\n.remove-option::after {\r\n  border-right: 2px solid #fff;\r\n  content: \"\";\r\n  height: 1em;\r\n  right: 0.75em;\r\n  position: absolute;\r\n  top: 50%;\r\n  width: 0;\r\n}\r\n\r\n.remove-option::before {\r\n  transform: translate(0, -50%) rotate(45deg);\r\n}\r\n\r\n.remove-option::after {\r\n  transform: translate(0, -50%) rotate(-45deg);\r\n}<\/pre>\n<p><span style=\"font-size: 14pt;\">function.js<\/span><\/p>\n<p>The final step, create a JavaScript file named &#8216;<em><strong>function.js<\/strong><\/em>&#8216; and put the codes.<\/p>\n<pre class=\"height-set:true height:750 lang:js decode:true \" title=\"function.js\">\/\/ Code By Webdevtrick ( https:\/\/webdevtrick.com )\r\nconst Keys = {\r\n  Backspace: 'Backspace',\r\n  Clear: 'Clear',\r\n  Down: 'ArrowDown',\r\n  End: 'End',\r\n  Enter: 'Enter',\r\n  Escape: 'Escape',\r\n  Home: 'Home',\r\n  Left: 'ArrowLeft',\r\n  PageDown: 'PageDown',\r\n  PageUp: 'PageUp',\r\n  Right: 'ArrowRight',\r\n  Space: ' ',\r\n  Tab: 'Tab',\r\n  Up: 'ArrowUp' };\r\n\r\n\r\nconst MenuActions = {\r\n  Close: 0,\r\n  CloseSelect: 1,\r\n  First: 2,\r\n  Last: 3,\r\n  Next: 4,\r\n  Open: 5,\r\n  Previous: 6,\r\n  Select: 7,\r\n  Space: 8,\r\n  Type: 9 };\r\n\r\n\r\n\/\/ filter an array of options against an input string\r\n\/\/ returns an array of options that begin with the filter string, case-independent\r\nfunction filterOptions(options = [], filter, exclude = []) {\r\n  return options.filter(option =&gt; {\r\n    const matches = option.toLowerCase().indexOf(filter.toLowerCase()) === 0;\r\n    return matches &amp;&amp; exclude.indexOf(option) &lt; 0;\r\n  });\r\n}\r\n\r\n\/\/ return an array of exact option name matches from a comma-separated string\r\nfunction findMatches(options, search) {\r\n  const names = search.split(',');\r\n  return names.map(name =&gt; {\r\n    const match = options.filter(option =&gt; name.trim().toLowerCase() === option.toLowerCase());\r\n    return match.length &gt; 0 ? match[0] : null;\r\n  }).\r\n  filter(option =&gt; option !== null);\r\n}\r\n\r\n\/\/ return combobox action from key press\r\nfunction getActionFromKey(event, menuOpen) {\r\n  const { key, altKey, ctrlKey, metaKey } = event;\r\n  \/\/ handle opening when closed\r\n  if (!menuOpen &amp;&amp; (key === Keys.Down || key === Keys.Enter || key === Keys.Space)) {\r\n    return MenuActions.Open;\r\n  }\r\n\r\n  \/\/ handle keys when open\r\n  if (key === Keys.Down) {\r\n    return MenuActions.Next;\r\n  } else\r\n  if (key === Keys.Up) {\r\n    return MenuActions.Previous;\r\n  } else\r\n  if (key === Keys.Home) {\r\n    return MenuActions.First;\r\n  } else\r\n  if (key === Keys.End) {\r\n    return MenuActions.Last;\r\n  } else\r\n  if (key === Keys.Escape) {\r\n    return MenuActions.Close;\r\n  } else\r\n  if (key === Keys.Enter) {\r\n    return MenuActions.CloseSelect;\r\n  } else\r\n  if (key === Keys.Space) {\r\n    return MenuActions.Space;\r\n  } else\r\n  if (key === Keys.Backspace || key === Keys.Clear || key.length === 1 &amp;&amp; !altKey &amp;&amp; !ctrlKey &amp;&amp; !metaKey) {\r\n    return MenuActions.Type;\r\n  }\r\n}\r\n\r\n\/\/ get index of option that matches a string\r\nfunction getIndexByLetter(options, filter) {\r\n  const firstMatch = filterOptions(options, filter)[0];\r\n  return firstMatch ? options.indexOf(firstMatch) : -1;\r\n}\r\n\r\n\/\/ get updated option index\r\nfunction getUpdatedIndex(current, max, action) {\r\n  switch (action) {\r\n    case MenuActions.First:\r\n      return 0;\r\n    case MenuActions.Last:\r\n      return max;\r\n    case MenuActions.Previous:\r\n      return Math.max(0, current - 1);\r\n    case MenuActions.Next:\r\n      return Math.min(max, current + 1);\r\n    default:\r\n      return current;}\r\n\r\n}\r\n\r\n\/\/ check if an element is currently scrollable\r\nfunction isScrollable(element) {\r\n  return element &amp;&amp; element.clientHeight &lt; element.scrollHeight;\r\n}\r\n\r\n\/\/ ensure given child element is within the parent's visible scroll area\r\nfunction maintainScrollVisibility(activeElement, scrollParent) {\r\n  const { offsetHeight, offsetTop } = activeElement;\r\n  const { offsetHeight: parentOffsetHeight, scrollTop } = scrollParent;\r\n\r\n  const isAbove = offsetTop &lt; scrollTop;\r\n  const isBelow = offsetTop + offsetHeight &gt; scrollTop + parentOffsetHeight;\r\n\r\n  if (isAbove) {\r\n    scrollParent.scrollTo(0, offsetTop);\r\n  } else\r\n  if (isBelow) {\r\n    scrollParent.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight);\r\n  }\r\n}\r\n\r\n\/*\r\n   * Editable Combobox code\r\n   *\/\r\nconst Combobox = function (el, options) {\r\n  \/\/ element refs\r\n  this.el = el;\r\n  this.inputEl = el.querySelector('input');\r\n  this.listboxEl = el.querySelector('[role=listbox]');\r\n\r\n  \/\/ data\r\n  this.idBase = this.inputEl.id;\r\n  this.options = options;\r\n\r\n  \/\/ state\r\n  this.activeIndex = 0;\r\n  this.open = false;\r\n};\r\n\r\nCombobox.prototype.init = function () {\r\n  this.inputEl.value = options[0];\r\n\r\n  this.inputEl.addEventListener('input', this.onInput.bind(this));\r\n  this.inputEl.addEventListener('blur', this.onInputBlur.bind(this));\r\n  this.inputEl.addEventListener('click', () =&gt; this.updateMenuState(true));\r\n  this.inputEl.addEventListener('keydown', this.onInputKeyDown.bind(this));\r\n\r\n  this.options.map((option, index) =&gt; {\r\n    const optionEl = document.createElement('div');\r\n    optionEl.setAttribute('role', 'option');\r\n    optionEl.id = `${this.idBase}-${index}`;\r\n    optionEl.className = index === 0 ? 'combo-option option-current' : 'combo-option';\r\n    optionEl.setAttribute('aria-selected', `${index === 0}`);\r\n    optionEl.innerText = option;\r\n\r\n    optionEl.addEventListener('click', () =&gt; {this.onOptionClick(index);});\r\n    optionEl.addEventListener('mousedown', this.onOptionMouseDown.bind(this));\r\n\r\n    this.listboxEl.appendChild(optionEl);\r\n  });\r\n};\r\n\r\nCombobox.prototype.onInput = function () {\r\n  const curValue = this.inputEl.value;\r\n  const matches = filterOptions(this.options, curValue);\r\n\r\n  \/\/ set activeIndex to first matching option\r\n  \/\/ (or leave it alone, if the active option is already in the matching set)\r\n  const filterCurrentOption = matches.filter(option =&gt; option === this.options[this.activeIndex]);\r\n  if (matches.length &gt; 0 &amp;&amp; !filterCurrentOption.length) {\r\n    this.onOptionChange(this.options.indexOf(matches[0]));\r\n  }\r\n\r\n  const menuState = this.options.length &gt; 0;\r\n  if (this.open !== menuState) {\r\n    this.updateMenuState(menuState, false);\r\n  }\r\n};\r\n\r\nCombobox.prototype.onInputKeyDown = function (event) {\r\n  const max = this.options.length - 1;\r\n\r\n  const action = getActionFromKey(event, this.open);\r\n\r\n  switch (action) {\r\n    case MenuActions.Next:\r\n    case MenuActions.Last:\r\n    case MenuActions.First:\r\n    case MenuActions.Previous:\r\n      event.preventDefault();\r\n      return this.onOptionChange(getUpdatedIndex(this.activeIndex, max, action));\r\n    case MenuActions.CloseSelect:\r\n      event.preventDefault();\r\n      this.selectOption(this.activeIndex);\r\n      return this.updateMenuState(false);\r\n    case MenuActions.Close:\r\n      event.preventDefault();\r\n      return this.updateMenuState(false);\r\n    case MenuActions.Open:\r\n      return this.updateMenuState(true);}\r\n\r\n};\r\n\r\nCombobox.prototype.onInputBlur = function () {\r\n  if (this.ignoreBlur) {\r\n    this.ignoreBlur = false;\r\n    return;\r\n  }\r\n\r\n  if (this.open) {\r\n    this.selectOption(this.activeIndex);\r\n    this.updateMenuState(false, false);\r\n  }\r\n};\r\n\r\nCombobox.prototype.onOptionChange = function (index) {\r\n  this.activeIndex = index;\r\n  this.inputEl.setAttribute('aria-activedescendant', `${this.idBase}-${index}`);\r\n\r\n  \/\/ update active style\r\n  const options = this.el.querySelectorAll('[role=option]');\r\n  [...options].forEach(optionEl =&gt; {\r\n    optionEl.classList.remove('option-current');\r\n  });\r\n  options[index].classList.add('option-current');\r\n\r\n  if (this.open &amp;&amp; isScrollable(this.listboxEl)) {\r\n    maintainScrollVisibility(options[index], this.listboxEl);\r\n  }\r\n};\r\n\r\nCombobox.prototype.onOptionClick = function (index) {\r\n  this.onOptionChange(index);\r\n  this.selectOption(index);\r\n  this.updateMenuState(false);\r\n};\r\n\r\nCombobox.prototype.onOptionMouseDown = function () {\r\n  this.ignoreBlur = true;\r\n};\r\n\r\nCombobox.prototype.selectOption = function (index) {\r\n  const selected = this.options[index];\r\n  this.inputEl.value = selected;\r\n  this.activeIndex = index;\r\n\r\n  \/\/ update aria-selected\r\n  const options = this.el.querySelectorAll('[role=option]');\r\n  [...options].forEach(optionEl =&gt; {\r\n    optionEl.setAttribute('aria-selected', 'false');\r\n  });\r\n  options[index].setAttribute('aria-selected', 'true');\r\n};\r\n\r\nCombobox.prototype.updateMenuState = function (open, callFocus = true) {\r\n  this.open = open;\r\n\r\n  this.inputEl.setAttribute('aria-expanded', `${open}`);\r\n  open ? this.el.classList.add('open') : this.el.classList.remove('open');\r\n  callFocus &amp;&amp; this.inputEl.focus();\r\n};\r\n\r\n\/\/ init combo\r\nconst comboEl = document.querySelector('.js-combobox');\r\nconst options = ['HTML', 'CSS', 'JavaScript', 'PHP', 'MySQL', 'React', 'Angular', 'Python'];\r\nconst comboComponent = new Combobox(comboEl, options);\r\ncomboComponent.init();\r\n\r\n\/*\r\n                        * Read-only select code\r\n                        *\/\r\nconst Select = function (el, options) {\r\n  \/\/ element refs\r\n  this.el = el;\r\n  this.comboEl = el.querySelector('[role=combobox]');\r\n  this.listboxEl = el.querySelector('[role=listbox]');\r\n\r\n  \/\/ data\r\n  this.idBase = this.comboEl.id;\r\n  this.options = options;\r\n\r\n  \/\/ state\r\n  this.activeIndex = 0;\r\n  this.open = false;\r\n};\r\n\r\nSelect.prototype.init = function () {\r\n  this.comboEl.innerHTML = options[0];\r\n\r\n  this.comboEl.addEventListener('blur', this.onComboBlur.bind(this));\r\n  this.comboEl.addEventListener('click', () =&gt; this.updateMenuState(true));\r\n  this.comboEl.addEventListener('keydown', this.onComboKeyDown.bind(this));\r\n\r\n  this.options.map((option, index) =&gt; {\r\n    const optionEl = document.createElement('div');\r\n    optionEl.setAttribute('role', 'option');\r\n    optionEl.id = `${this.idBase}-${index}`;\r\n    optionEl.className = index === 0 ? 'combo-option option-current' : 'combo-option';\r\n    optionEl.setAttribute('aria-selected', `${index === 0}`);\r\n    optionEl.innerText = option;\r\n\r\n    optionEl.addEventListener('click', event =&gt; {\r\n      event.stopPropagation();\r\n      this.onOptionClick(index);\r\n    });\r\n    optionEl.addEventListener('mousedown', this.onOptionMouseDown.bind(this));\r\n\r\n    this.listboxEl.appendChild(optionEl);\r\n  });\r\n};\r\n\r\nSelect.prototype.onComboKeyDown = function (event) {\r\n  const { key } = event;\r\n  const max = this.options.length - 1;\r\n\r\n  const action = getActionFromKey(event, this.open);\r\n\r\n  switch (action) {\r\n    case MenuActions.Next:\r\n    case MenuActions.Last:\r\n    case MenuActions.First:\r\n    case MenuActions.Previous:\r\n      event.preventDefault();\r\n      return this.onOptionChange(getUpdatedIndex(this.activeIndex, max, action));\r\n    case MenuActions.CloseSelect:\r\n    case MenuActions.Space:\r\n      event.preventDefault();\r\n      this.selectOption(this.activeIndex);\r\n    case MenuActions.Close:\r\n      event.preventDefault();\r\n      return this.updateMenuState(false);\r\n    case MenuActions.Type:\r\n      this.updateMenuState(true);\r\n      return this.onOptionChange(Math.max(0, getIndexByLetter(this.options, key)));\r\n    case MenuActions.Open:\r\n      event.preventDefault();\r\n      return this.updateMenuState(true);}\r\n\r\n};\r\n\r\nSelect.prototype.onComboBlur = function () {\r\n  if (this.ignoreBlur) {\r\n    this.ignoreBlur = false;\r\n    return;\r\n  }\r\n\r\n  if (this.open) {\r\n    this.selectOption(this.activeIndex);\r\n    this.updateMenuState(false, false);\r\n  }\r\n};\r\n\r\nSelect.prototype.onOptionChange = function (index) {\r\n  this.activeIndex = index;\r\n  this.comboEl.setAttribute('aria-activedescendant', `${this.idBase}-${index}`);\r\n\r\n  \/\/ update active style\r\n  const options = this.el.querySelectorAll('[role=option]');\r\n  [...options].forEach(optionEl =&gt; {\r\n    optionEl.classList.remove('option-current');\r\n  });\r\n  options[index].classList.add('option-current');\r\n\r\n  if (isScrollable(this.listboxEl)) {\r\n    maintainScrollVisibility(options[index], this.listboxEl);\r\n  }\r\n};\r\n\r\nSelect.prototype.onOptionClick = function (index) {\r\n  this.onOptionChange(index);\r\n  this.selectOption(index);\r\n  this.updateMenuState(false);\r\n};\r\n\r\nSelect.prototype.onOptionMouseDown = function () {\r\n  this.ignoreBlur = true;\r\n};\r\n\r\nSelect.prototype.selectOption = function (index) {\r\n  const selected = this.options[index];\r\n  this.comboEl.innerHTML = selected;\r\n  this.activeIndex = index;\r\n\r\n  \/\/ update aria-selected\r\n  const options = this.el.querySelectorAll('[role=option]');\r\n  [...options].forEach(optionEl =&gt; {\r\n    optionEl.setAttribute('aria-selected', 'false');\r\n  });\r\n  options[index].setAttribute('aria-selected', 'true');\r\n};\r\n\r\nSelect.prototype.updateMenuState = function (open, callFocus = true) {\r\n  this.open = open;\r\n\r\n  this.comboEl.setAttribute('aria-expanded', `${open}`);\r\n  open ? this.el.classList.add('open') : this.el.classList.remove('open');\r\n  callFocus &amp;&amp; this.comboEl.focus();\r\n};\r\n\r\n\/\/ init select\r\nconst selectEl = document.querySelector('.js-select');\r\nconst selectComponent = new Select(selectEl, options);\r\nselectComponent.init();\r\n\r\n\/*\r\n                         * Multiselect code\r\n                         *\/\r\nconst Multiselect = function (el, options) {\r\n  \/\/ element refs\r\n  this.el = el;\r\n  this.inputEl = el.querySelector('input');\r\n  this.listboxEl = el.querySelector('[role=listbox]');\r\n\r\n  this.idBase = this.inputEl.id;\r\n  this.selectedEl = document.getElementById(`${this.idBase}-selected`);\r\n\r\n  \/\/ data\r\n  this.options = options;\r\n\r\n  \/\/ state\r\n  this.activeIndex = 0;\r\n  this.open = false;\r\n};\r\n\r\nMultiselect.prototype.init = function () {\r\n  this.inputEl.addEventListener('input', this.onInput.bind(this));\r\n  this.inputEl.addEventListener('blur', this.onInputBlur.bind(this));\r\n  this.inputEl.addEventListener('click', () =&gt; this.updateMenuState(true));\r\n  this.inputEl.addEventListener('keydown', this.onInputKeyDown.bind(this));\r\n  this.listboxEl.addEventListener('blur', this.onInputBlur.bind(this));\r\n\r\n  this.options.map((option, index) =&gt; {\r\n    const optionEl = document.createElement('div');\r\n    optionEl.setAttribute('role', 'option');\r\n    optionEl.id = `${this.idBase}-${index}`;\r\n    optionEl.className = index === 0 ? 'combo-option option-current' : 'combo-option';\r\n    optionEl.setAttribute('aria-selected', 'false');\r\n    optionEl.innerText = option;\r\n\r\n    optionEl.addEventListener('click', () =&gt; {this.onOptionClick(index);});\r\n    optionEl.addEventListener('mousedown', this.onOptionMouseDown.bind(this));\r\n\r\n    this.listboxEl.appendChild(optionEl);\r\n  });\r\n};\r\n\r\nMultiselect.prototype.onInput = function () {\r\n  const curValue = this.inputEl.value;\r\n  const matches = filterOptions(this.options, curValue);\r\n\r\n  \/\/ set activeIndex to first matching option\r\n  \/\/ (or leave it alone, if the active option is already in the matching set)\r\n  const filterCurrentOption = matches.filter(option =&gt; option === this.options[this.activeIndex]);\r\n  if (matches.length &gt; 0 &amp;&amp; !filterCurrentOption.length) {\r\n    this.onOptionChange(this.options.indexOf(matches[0]));\r\n  }\r\n\r\n  const menuState = this.options.length &gt; 0;\r\n  if (this.open !== menuState) {\r\n    this.updateMenuState(menuState, false);\r\n  }\r\n};\r\n\r\nMultiselect.prototype.onInputKeyDown = function (event) {\r\n  const max = this.options.length - 1;\r\n\r\n  const action = getActionFromKey(event, this.open);\r\n\r\n  switch (action) {\r\n    case MenuActions.Next:\r\n    case MenuActions.Last:\r\n    case MenuActions.First:\r\n    case MenuActions.Previous:\r\n      event.preventDefault();\r\n      return this.onOptionChange(getUpdatedIndex(this.activeIndex, max, action));\r\n    case MenuActions.CloseSelect:\r\n      event.preventDefault();\r\n      return this.updateOption(this.activeIndex);\r\n    case MenuActions.Close:\r\n      event.preventDefault();\r\n      return this.updateMenuState(false);\r\n    case MenuActions.Open:\r\n      return this.updateMenuState(true);}\r\n\r\n};\r\n\r\nMultiselect.prototype.onInputBlur = function () {\r\n  if (this.ignoreBlur) {\r\n    this.ignoreBlur = false;\r\n    return;\r\n  }\r\n\r\n  if (this.open) {\r\n    this.updateMenuState(false, false);\r\n  }\r\n};\r\n\r\nMultiselect.prototype.onOptionChange = function (index) {\r\n  this.activeIndex = index;\r\n  this.inputEl.setAttribute('aria-activedescendant', `${this.idBase}-${index}`);\r\n\r\n  \/\/ update active style\r\n  const options = this.el.querySelectorAll('[role=option]');\r\n  [...options].forEach(optionEl =&gt; {\r\n    optionEl.classList.remove('option-current');\r\n  });\r\n  options[index].classList.add('option-current');\r\n\r\n  if (this.open &amp;&amp; isScrollable(this.listboxEl)) {\r\n    maintainScrollVisibility(options[index], this.listboxEl);\r\n  }\r\n};\r\n\r\nMultiselect.prototype.onOptionClick = function (index) {\r\n  this.onOptionChange(index);\r\n  this.updateOption(index);\r\n  this.inputEl.focus();\r\n};\r\n\r\nMultiselect.prototype.onOptionMouseDown = function () {\r\n  this.ignoreBlur = true;\r\n};\r\n\r\nMultiselect.prototype.removeOption = function (index) {\r\n  const option = this.options[index];\r\n\r\n  \/\/ update aria-selected\r\n  const options = this.el.querySelectorAll('[role=option]');\r\n  options[index].setAttribute('aria-selected', 'false');\r\n  options[index].classList.remove('option-selected');\r\n\r\n  \/\/ remove button\r\n  const buttonEl = document.getElementById(`${this.idBase}-remove-${index}`);\r\n  this.selectedEl.removeChild(buttonEl.parentElement);\r\n};\r\n\r\nMultiselect.prototype.selectOption = function (index) {\r\n  const selected = this.options[index];\r\n  this.activeIndex = index;\r\n\r\n  \/\/ update aria-selected\r\n  const options = this.el.querySelectorAll('[role=option]');\r\n  options[index].setAttribute('aria-selected', 'true');\r\n  options[index].classList.add('option-selected');\r\n\r\n  \/\/ add remove option button\r\n  const buttonEl = document.createElement('button');\r\n  const listItem = document.createElement('li');\r\n  buttonEl.className = 'remove-option';\r\n  buttonEl.type = 'button';\r\n  buttonEl.id = `${this.idBase}-remove-${index}`;\r\n  buttonEl.setAttribute('aria-describedby', `${this.idBase}-remove`);\r\n  buttonEl.addEventListener('click', () =&gt; {this.removeOption(index);});\r\n  buttonEl.innerHTML = selected + ' ';\r\n\r\n  listItem.appendChild(buttonEl);\r\n  this.selectedEl.appendChild(listItem);\r\n};\r\n\r\nMultiselect.prototype.updateOption = function (index) {\r\n  const option = this.options[index];\r\n  const optionEl = this.el.querySelectorAll('[role=option]')[index];\r\n  const isSelected = optionEl.getAttribute('aria-selected') === 'true';\r\n\r\n  if (isSelected) {\r\n    this.removeOption(index);\r\n  } else\r\n\r\n  {\r\n    this.selectOption(index);\r\n  }\r\n\r\n  this.inputEl.value = '';\r\n};\r\n\r\nMultiselect.prototype.updateMenuState = function (open, callFocus = true) {\r\n  this.open = open;\r\n\r\n  this.inputEl.setAttribute('aria-expanded', `${open}`);\r\n  open ? this.el.classList.add('open') : this.el.classList.remove('open');\r\n  callFocus &amp;&amp; this.inputEl.focus();\r\n};\r\n\r\n\/\/ init multiselect\r\nconst multiselectEl = document.querySelector('.js-multiselect');\r\nconst multiselectComponent = new Multiselect(multiselectEl, options);\r\nmultiselectComponent.init();<\/pre>\n<p>That&#8217;s It. Now you have successfully created <strong>HTML Combobox With JavaScript and CSS<\/strong>, <strong>Combobox Types and Patterns<\/strong>. If you have any doubt or question comment down below.<\/p>\n<p><span style=\"font-family: impact, sans-serif;\">Thanks For Visiting, Keep Visiting.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How we can create a Combobox pattern using HTML CSS JS? Solution: See this HTML combo box With JavaScript and CSS, Combobox Types &amp; Patterns. Previously I have shared some select option programs, this is also like that but it is a combo box. Basically, A combo box is a commonly used graphical user interface [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5640,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[43,42,46],"tags":[536,537,330,61,165,245,246,67],"class_list":["post-5639","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css","category-html","category-javascript","tag-combo-box","tag-combobox","tag-dropdown","tag-javascript-tips-and-tricks","tag-key-detect","tag-option","tag-select","tag-source-code"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>HTML Combobox With JavaScript and CSS | Combobox Types &amp; Patterns<\/title>\n<meta name=\"description\" content=\"Want to create a combo box? Checkout this HTML Combobox with JavaScript and CSS, Combobox Types: simple, editable, and multi select. Get source code now.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"HTML Combobox With JavaScript and CSS | Combobox Types &amp; Patterns\" \/>\n<meta property=\"og:description\" content=\"Want to create a combo box? Checkout this HTML Combobox with JavaScript and CSS, Combobox Types: simple, editable, and multi select. Get source code now.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Dev Trick\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webdevtrick\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-28T08:19:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-28T15:33:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webdevtrick.com\/wp-content\/uploads\/html-combobox-with-javascript.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"shaan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"shaan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/\"},\"author\":{\"name\":\"shaan\",\"@id\":\"https:\/\/webdevtrick.com\/#\/schema\/person\/c79bae83976f92fe305c22342b2a0be3\"},\"headline\":\"HTML Combobox With JavaScript and CSS | Combobox Types &#038; Patterns\",\"datePublished\":\"2020-04-28T08:19:00+00:00\",\"dateModified\":\"2020-04-28T15:33:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/\"},\"wordCount\":658,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\/\/webdevtrick.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webdevtrick.com\/wp-content\/uploads\/html-combobox-with-javascript.jpg\",\"keywords\":[\"combo box\",\"combobox\",\"dropdown\",\"javascript tips and tricks\",\"key detect\",\"option\",\"select\",\"source code\"],\"articleSection\":[\"CSS\",\"HTML\",\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/\",\"url\":\"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/\",\"name\":\"HTML Combobox With JavaScript and CSS | Combobox Types & Patterns\",\"isPartOf\":{\"@id\":\"https:\/\/webdevtrick.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webdevtrick.com\/wp-content\/uploads\/html-combobox-with-javascript.jpg\",\"datePublished\":\"2020-04-28T08:19:00+00:00\",\"dateModified\":\"2020-04-28T15:33:45+00:00\",\"description\":\"Want to create a combo box? Checkout this HTML Combobox with JavaScript and CSS, Combobox Types: simple, editable, and multi select. Get source code now.\",\"breadcrumb\":{\"@id\":\"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#primaryimage\",\"url\":\"https:\/\/webdevtrick.com\/wp-content\/uploads\/html-combobox-with-javascript.jpg\",\"contentUrl\":\"https:\/\/webdevtrick.com\/wp-content\/uploads\/html-combobox-with-javascript.jpg\",\"width\":1200,\"height\":630,\"caption\":\"html combobox with javascript\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webdevtrick.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HTML Combobox With JavaScript and CSS | Combobox Types &#038; Patterns\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webdevtrick.com\/#website\",\"url\":\"https:\/\/webdevtrick.com\/\",\"name\":\"Web Dev Trick\",\"description\":\"HTML5, CSS3, JS, PHP Source Code &amp; Tutorial\",\"publisher\":{\"@id\":\"https:\/\/webdevtrick.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webdevtrick.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webdevtrick.com\/#organization\",\"name\":\"Web Dev Trick\",\"url\":\"https:\/\/webdevtrick.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webdevtrick.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/webdevtrick.com\/wp-content\/uploads\/logo-fb-1.png\",\"contentUrl\":\"https:\/\/webdevtrick.com\/wp-content\/uploads\/logo-fb-1.png\",\"width\":512,\"height\":512,\"caption\":\"Web Dev Trick\"},\"image\":{\"@id\":\"https:\/\/webdevtrick.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webdevtrick\/\",\"https:\/\/pinterest.com\/webdevtrick\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webdevtrick.com\/#\/schema\/person\/c79bae83976f92fe305c22342b2a0be3\",\"name\":\"shaan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webdevtrick.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/60aa6ee93605bda7bc598d11dd748709a69bdb55a080124cc382114d8d7e7665?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/60aa6ee93605bda7bc598d11dd748709a69bdb55a080124cc382114d8d7e7665?s=96&d=mm&r=g\",\"caption\":\"shaan\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HTML Combobox With JavaScript and CSS | Combobox Types & Patterns","description":"Want to create a combo box? Checkout this HTML Combobox with JavaScript and CSS, Combobox Types: simple, editable, and multi select. Get source code now.","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:\/\/webdevtrick.com\/html-combobox-with-javascript\/","og_locale":"en_US","og_type":"article","og_title":"HTML Combobox With JavaScript and CSS | Combobox Types & Patterns","og_description":"Want to create a combo box? Checkout this HTML Combobox with JavaScript and CSS, Combobox Types: simple, editable, and multi select. Get source code now.","og_url":"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/","og_site_name":"Web Dev Trick","article_publisher":"https:\/\/www.facebook.com\/webdevtrick\/","article_published_time":"2020-04-28T08:19:00+00:00","article_modified_time":"2020-04-28T15:33:45+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/webdevtrick.com\/wp-content\/uploads\/html-combobox-with-javascript.jpg","type":"image\/jpeg"}],"author":"shaan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"shaan","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#article","isPartOf":{"@id":"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/"},"author":{"name":"shaan","@id":"https:\/\/webdevtrick.com\/#\/schema\/person\/c79bae83976f92fe305c22342b2a0be3"},"headline":"HTML Combobox With JavaScript and CSS | Combobox Types &#038; Patterns","datePublished":"2020-04-28T08:19:00+00:00","dateModified":"2020-04-28T15:33:45+00:00","mainEntityOfPage":{"@id":"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/"},"wordCount":658,"commentCount":5,"publisher":{"@id":"https:\/\/webdevtrick.com\/#organization"},"image":{"@id":"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/webdevtrick.com\/wp-content\/uploads\/html-combobox-with-javascript.jpg","keywords":["combo box","combobox","dropdown","javascript tips and tricks","key detect","option","select","source code"],"articleSection":["CSS","HTML","JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/","url":"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/","name":"HTML Combobox With JavaScript and CSS | Combobox Types & Patterns","isPartOf":{"@id":"https:\/\/webdevtrick.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#primaryimage"},"image":{"@id":"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/webdevtrick.com\/wp-content\/uploads\/html-combobox-with-javascript.jpg","datePublished":"2020-04-28T08:19:00+00:00","dateModified":"2020-04-28T15:33:45+00:00","description":"Want to create a combo box? Checkout this HTML Combobox with JavaScript and CSS, Combobox Types: simple, editable, and multi select. Get source code now.","breadcrumb":{"@id":"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webdevtrick.com\/html-combobox-with-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#primaryimage","url":"https:\/\/webdevtrick.com\/wp-content\/uploads\/html-combobox-with-javascript.jpg","contentUrl":"https:\/\/webdevtrick.com\/wp-content\/uploads\/html-combobox-with-javascript.jpg","width":1200,"height":630,"caption":"html combobox with javascript"},{"@type":"BreadcrumbList","@id":"https:\/\/webdevtrick.com\/html-combobox-with-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webdevtrick.com\/"},{"@type":"ListItem","position":2,"name":"HTML Combobox With JavaScript and CSS | Combobox Types &#038; Patterns"}]},{"@type":"WebSite","@id":"https:\/\/webdevtrick.com\/#website","url":"https:\/\/webdevtrick.com\/","name":"Web Dev Trick","description":"HTML5, CSS3, JS, PHP Source Code &amp; Tutorial","publisher":{"@id":"https:\/\/webdevtrick.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webdevtrick.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webdevtrick.com\/#organization","name":"Web Dev Trick","url":"https:\/\/webdevtrick.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webdevtrick.com\/#\/schema\/logo\/image\/","url":"https:\/\/webdevtrick.com\/wp-content\/uploads\/logo-fb-1.png","contentUrl":"https:\/\/webdevtrick.com\/wp-content\/uploads\/logo-fb-1.png","width":512,"height":512,"caption":"Web Dev Trick"},"image":{"@id":"https:\/\/webdevtrick.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webdevtrick\/","https:\/\/pinterest.com\/webdevtrick\/"]},{"@type":"Person","@id":"https:\/\/webdevtrick.com\/#\/schema\/person\/c79bae83976f92fe305c22342b2a0be3","name":"shaan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webdevtrick.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/60aa6ee93605bda7bc598d11dd748709a69bdb55a080124cc382114d8d7e7665?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/60aa6ee93605bda7bc598d11dd748709a69bdb55a080124cc382114d8d7e7665?s=96&d=mm&r=g","caption":"shaan"}}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webdevtrick.com\/wp-json\/wp\/v2\/posts\/5639","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webdevtrick.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webdevtrick.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webdevtrick.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webdevtrick.com\/wp-json\/wp\/v2\/comments?post=5639"}],"version-history":[{"count":11,"href":"https:\/\/webdevtrick.com\/wp-json\/wp\/v2\/posts\/5639\/revisions"}],"predecessor-version":[{"id":6087,"href":"https:\/\/webdevtrick.com\/wp-json\/wp\/v2\/posts\/5639\/revisions\/6087"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webdevtrick.com\/wp-json\/wp\/v2\/media\/5640"}],"wp:attachment":[{"href":"https:\/\/webdevtrick.com\/wp-json\/wp\/v2\/media?parent=5639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webdevtrick.com\/wp-json\/wp\/v2\/categories?post=5639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webdevtrick.com\/wp-json\/wp\/v2\/tags?post=5639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}