How to add input text in select option dropdown

15,270

You can try <datalist>:

The HTML <datalist> element contains a set of elements that represent the values available for other controls.

<input list="select" name="select">
<datalist class="form-control" id="select">    
  <option value="Trans"/>
  <option value="Fund"/>
  <option value="Insta"/>
</datalist>
Share:
15,270

Related videos on Youtube

mia
Author by

mia

Updated on June 04, 2022

Comments

  • mia
    mia almost 2 years

    I would like to know how to add input text box to the select dropdown and use it as search filter in javascript.

    <select class="form-control">
        <option value="trans">Trans</option>
        <option value="fund">Fund</option>
        <option value="insta">Insta</option>
    </select>
    
    
    • JIJOMON K.A
      JIJOMON K.A about 5 years
    • mia
      mia about 5 years
      @JIJOMONK.A thanks for reply, can use javascript not jquery
  • LazZiya
    LazZiya about 5 years
    This is good, is it possible to restrict the input to the list items only?
  • Mamun
    Mamun about 5 years
    @LazZiya, the input is already bound to the list items by linking the attribute id and list:)
  • Admin
    Admin about 5 years
    It is a plugin of jquery , So you have to link that url aswell
  • LazZiya
    LazZiya about 5 years
    but still the input can accept something else not defined in the datalist. right?
  • Mamun
    Mamun about 5 years
    @LazZiya, now I got what you are meaning, for that we have to write additional code on the input event of the control:)
  • mia
    mia about 5 years
    thanks but have edited the code according to requirement, I have to add text input inside select, please review code
  • mia
    mia about 5 years
    thanks but have edited the code according to requirement in Laz Ziya post, I have to add text input inside select, please review code
  • LazZiya
    LazZiya about 5 years
    I reviewed your edit, it breaks the code and didn't work, it doesn't seem a practical way to deal with select input in this case
  • Fakhamatia
    Fakhamatia over 4 years
    it's not working on the touch keyboard, why? should I send a keypress trigger?