Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an input type text look like select dropdown?

Is there any way by which I can make an input type=text element look like a dropdown? Currently I have a text box which when clicked I am displaying options using jquery and div. I want the text box to have a drop down icon to make it exactly look like a regular dropdown.

Also since different browsers have different dropdown icon is there a way to use the same dropdown icon that the browser provides?

Note: I have to apply some css to the option values before displaying it which I cant do using regular dropdown. That is why I have used div and jquery to display the option values.

like image 912
Sachin B. R. Avatar asked May 26 '15 06:05

Sachin B. R.


People also ask

What is the input type for dropdown?

The <datalist> Element Users will see a drop-down list of the pre-defined options as they input data. The list attribute of the <input> element, must refer to the id attribute of the <datalist> element.

How do I activate a TextBox if I select an option in drop down box?

When an item (option) is selected in DropDownList (HTML SELECT), the EnableDisableTextBox JavaScript function is executed. Inside this function, based on whether the Other option (item) is selected, the TextBox will be enabled else disabled. The HTML Markup consists of a DropDownList (HTML SELECT) and a TextBox.


1 Answers

Try this example!

<div>Choose a browser from this list:</div>
<input list="browsers" />
<datalist id="browsers">
  <option value="Chrome">
  <option value="Firefox">
  <option value="Internet Explorer">
  <option value="Opera">
  <option value="Safari">
</datalist>

<div>Choose a browser from this list:</div>
    <input list="browsers" />
    <datalist id="browsers">
      <option value="Chrome">
      <option value="Firefox">
      <option value="Internet Explorer">
      <option value="Opera">
      <option value="Safari">
    </datalist>
like image 79
Joakim M Avatar answered Oct 17 '22 16:10

Joakim M