Reputation: 723
I have written a script that takes a pull down <select>
on a web page, and adds a multiple
attribute to the <select>
so that multiple options can be picked. However, when "multiple" is set my <select>
element loses its dropdown arrow and turns into a select box with no drop down. Is there any way to set a select to accept multiple options while retaining it as a drop down on the web page? The script is rather long as it uses other information on the page to determine if the <select>
needs to but multiple or single select, the code which changes this attribute is below.
if (Qtype === "Multi-Select") {
select_elem.setAttribute("multiple", "multiple");
}
if (Qtype === "Single-Select") {
select_elem.removeAttribute("multiple");
}
Upvotes: 1
Views: 136
Reputation: 50
When you add the multiple attribute to the select it changes the control to a select box by default (to let the user pick more than one option).
An easy way to get your desired behavior is by using a plugin.
One plugin to do this (there are many more) is: multiple-select.js (It is a jQuery plugin)
Upvotes: 2