0

I am trying to create a multiselect dropdown in a page where there are many users and dropdown box for each users. I am using jquery multiselect like this:

var handleMultiSelect = function () {
    $('#my_multi_select1').multiSelect({
        selectableOptgroup: true
    });
    $('#my_multi_select2').multiSelect({
        selectableOptgroup: true
    });
}

This is working but only for the first 2 multi select box. Lets say I have 100+ users in the page, how do I create separate ID for each of them? Thanks in advance.

Steve
  • 1,553
  • 2
  • 20
  • 29
pyfl88
  • 1,680
  • 16
  • 26
  • why not use class instead of id. – Rahul Singh Aug 07 '16 at 17:06
  • Can you give us some use cases for your select elements? How do you intend for the user and your app to use them? Do you read selections from them separately or as a group? Do you clear their selections separately or as a group? – MarsAtomic Aug 07 '16 at 18:30

1 Answers1

1

You can simply use a class instead of an id (ids are good for unique components, classes for multiples ones):

var handleMultiSelect = function () {
    $('.multiselectable').multiSelect({
        selectableOptgroup: true
    });
}

Then in the HTML, have your element class accoringly:

<select class="multiselectable"> ... </select>

More about id vs class here: Difference between id and class in CSS and when to use it

Community
  • 1
  • 1
Martin
  • 7,634
  • 1
  • 20
  • 23