multiselect – a jQueryUI form widget
Welcome to the multiselect project page! multiselect is a jQuery UI plugin that transforms a form select combobox into a dropdown menu, that utilizes YOUR jQueryUI theme!
Requirements
To use multiselect, it is recommended that you use jQuery version 1.6+. Reference the jQuery library followed the multiselect JavaScript file:
<!-- load jQuery library --> <script src="/common/js/libs/jquery-1.6.min.js"></script> <!-- load multiselect plugin --> <script src="jquery.ui.multiselect.js"></script>
Now you are ready to use multiselect! Below is some example code on the ways you can use it.
Simple Multiselect
The easiest way to create the multiselect widget is to just call it on a <select> element.
<!-- transform a select box -->
<script>
$('select').multiselect();
</script>
Multiselect w/ Options
- change: callback function for when an item is deselected or selected
- deselect: callback function for when an item is deselected
- label: sets the label for the dropdown widget (default is ‘– Select Option –’)
- minWidth: sets the minimum width of the dropdown widget (default is 200)
- maxWidth: sets the maximum width of the dropwdown before wrapping (no default set)
- scroll: sets the height of the dropdown options before scrolling (default is 0, no scrolling)
- select: callback function for when an item is selected
<!-- set your options -->
<script>
$('select').multiselect({
change: function() { console.log(this, 'changed'); },
deselect: function() { console.log(this, 'deselected'); },
label: 'Select Your Options', // default is '-- Select Option --'
minWidth: 300, // default is 200
maxWidth: 300, // no default max width
scroll: 400,
select: function() { console.log(this, 'selected'); },
});
</script>
Initial Select (Pre-select)
If you want to have items initially selected by default, all you have to do is call the ‘select’ option of the plugin and pass it the index of the option you want to select.
$('select').multiselect('select', 0); // selects the first option
$('select').multiselect('select', 1); // selects the second option
// etc

{ 10 comments… read them below or add one }
Hey,
the script looks really nice but do you know a way to enable a pre-selection support?
so that selected=”selected” is included the script preselects the values and puts them into the list?
regards
Ah, nice question. I’ve added this to the documentation above. Hope this helps!
Very, very nice plugin!
Nice plugin, but I’ve got a question:
What method do I have to use to use onchange with multiselect? I’ve tried onchange, onblur, and onclick on the parent . I thought of using onblur for the dropdown created by multiselect, but I don’t want it firing without a selection. I know it can be worked-around with a global variable or something, but I’d like to avoid that.
Never mind, I think I figured it out. I tried binding click on .ui-menu-item, and that seems to work.
I found that , it will auto submit if you select any option when we put this plugin in a form. Can help me?
Here is my part codes:
Foo
Bar
Foo Bar
@leo-
nice catch. this has been fixed. you can download the latest file on GitHub. Thanks.
You can find more information here:
https://github.com/corydorning/multiselect/commit/cd737a0fe25b91f53374019688488c6d6b7c9e2d
I am using this script for drop down menu with multi select check boxes. http://www.roseindia.net/tutorial/jsp/dropdown_checkbox.html
This particular script shows the following: If someone selects the the check box the name corresponding to the check box shows up. If Some one checks the box for New York , then New York shows up.
I want it to show number of values selected of the total number of values present. If Some one checks the box for New York , then I want it to show 1 of 20
I want it like this: Please check the first demo in the link:
http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/
Kindly let me know how I can do this?
While I don’t have an option to get the count of selected items, you could do one of 2 things…
1. Extend the plugin to include a callback (which I may add in the future, pretty busy as of late) which could then get the count of the number of items checked.
2. You could add a ‘change’ event handler to your list of checkboxes, which then runs a function to get the count of those ‘:checked’ and update your status message “xx checked of xx”.
Added new options for callback functions: change, deselect and select. You could use this to update your status text.