HTML/PHP one line dropdown list multiple selection

10,346

I suggest to use select2 which gives you an easy possibility to create such a select-box you need. Example from that page fitting your needs:

$(".js-example-basic-multiple").select2();

<select class="js-example-basic-multiple" multiple="multiple">
    <option value="AL">Alabama</option>
    ...
    <option value="WY">Wyoming</option>
</select>
Share:
10,346
user1260310
Author by

user1260310

Updated on June 11, 2022

Comments

  • user1260310
    user1260310 about 2 years

    does anyone know a way to create a dropdown list as in a select statement that allows multiple selections but can display on one line. Adding the multiple="multiple" option causes it to display on as many lines as there are options which is not suitable for this project's layout Css and/or javascript would be fine however, hoping to avoid js frameworks. Thinking something with onclick event to show the standard multi-line dropdown box might work but not sure how to implement.

    Following displays on several lines.

     <select name="items[ ]" multiple="multiple">
        <option value="item1">item1</option>
         <option value="item2">item2</option>
        <option value="item2">item2</option></select>
    
  • user1260310
    user1260310 about 12 years
    When you set size=1, you lose access to the other options, ie you can only see the first one.
  • simshaun
    simshaun about 12 years
    I mis-understood what you were asking then. Check out github.com/ehynds/jquery-ui-multiselect-widget
  • devios1
    devios1 over 11 years
    -1 as this simply doesn't work. I suggest editing your answer to suggest the jquery option instead of just leaving it in a comment.
  • zgr024
    zgr024 about 9 years
    While the op wanted to avoid using js frameworks, this is still the best answer. No sense in reinventing the wheel.