Multiselectable jQuery plugin

A Progressive Enhancement to <select multiple>

Selecting multiple values on a standard <select multiple> HTML control is an overwhelming task for a normal person. For a skilled computer user it is an exercise in frustration at best.

Multiselectable removes the issue of using keyboard modifiers to make a selection. It also makes it easier to see what elements are actually selected.

Multiselectable is certainly not a new idea. However, I could not find a proper implementation in jQuery. There have been other, not so traditional solutions to this problem as well.

Download Multiselectable

Multiselectable will turn this…

…into this:

How to Use

You must include the jQuery library, multiselectable.js and a one line of JavaScript to activate Multiselectable on the select element you choose. Here is an example how this page uses the plugin:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"
	type="text/javascript"></script>
<script src="multiselectable.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
	$('.multi').multiselectable();
});
</script>

Here is some useful CSS you should also include to your page if you want it to resemble usable:

.multiselectable { width:500px; display:block; overflow: auto; width: 100%; }
.multiselectable select, .multiselectable div { width: 200px; float:left; }
.multiselectable div * { display: block; margin: 0 auto; }
.multiselectable div { display: inline; }
.multiselectable .m-selectable-controls { margin-top: 3em; width: 50px; }
.multiselectable .m-selectable-controls button { margin-top: 1em; }

You can customize the default markup to suit your needs, just keep the class names and id:s intact. However, if you just need to change the labels or the button text, you can set them easily. Here is an example:

<script type="text/javascript">
$(document).ready(function() {
	$('.multi').multiselectable({
		selectableLabel: 'All countries',
		selectedLabel: 'Countries I\'ve visited',
		moveRightText: '+',
		moveLeftText: '-'
	});
});
</script>

Some Additional Niceties

  1. If you include the SortOptions plugin from the Select box manipulation plugin collection, then by default the options will be sorted automatically. Options will remain in their order even if they are transferred back and forth.
  2. Double-clicking an option will move it to the other side.
  3. Hitting the enter key will move selected options.

Technical Details for Server-side Developers

Multiselectable hides the original select element but does not remove it from the page. Multiselectable updates the original options to match those that are transferred right. This means that it should not interfere with any kind of sane server-side technology.

Accessibility

Multiselectable is fully functional using only a keyboard. Labels correctly point to the right elements, even when there are multiple Multiselectable controls within the page.

Licence and Copyright

Multiselectable copyright © Aki Björklund, 2009. Licenced under MIT.

Download Multiselectable


Comments (8)

Ramola Gokhale wrote (#):

Do you know how to add a “search” box to multiselectable element?

net wrote (#):

Hello,
Any chance you could provide a version compatible with jQuery 1.4.2? It would be greatly appreciated.

Aki Björklund wrote (#):

This page is actually running 1.4.2 (even thou the example states otherwise) and it looks like it’s working ok to me. What seems to be the problem?

net wrote (#):

I have the problem in IE (7 and 8). When I select one of the options and press the button to move it to the selected options, it disappears from the not-selected options but it does not appear on the selected ones.

I was suspecting some strange behavior of the clone() function, but it is really difficult to pinpoint the issue in IE…

net wrote (#):

By the way, on the page it seems to be working for me as well in IE, so the problem lies somewhere in my code…
Thank you anyway for your quick answer!

Aki Björklund wrote (#):

OK, thanks! I will get into it soon, probably over the weekend.

Aki Björklund wrote (#):

Oh, that is a relief. :) But I should release an updated version anyway.

Hendrik wrote (#):

Hi Aki,

Looks like it is not working in IE 7, but it is in IE 8. So it is probably not jQuery related.

It looks like the option is moved between the from and to select controls, but the behaviour of the control breaks after doing this. We use your control on a form page, where the value gets posted correctly to the server, which means that the value is correctly added to the other selector.

If you could look into this (with IE 7) and possibly fix this, that would be great!

Regards, Hendrik