jQuery multivalue selector

452 views Asked by At

Do you know of any good way/plugin to do this with jquery or any description on how to approach this effectively.

Simple layout of multi value selector

2

There are 2 answers

2
aendra On BEST ANSWER

This seems like what you're looking for:

"Easy Multi-Select Transfer with jQuery"

http://blog.jeremymartin.name/2008/02/easy-multi-select-transfer-with-jquery.html

Quick snippet, assumes you have two select lists ID'd #select 1 and #select2, as well as two buttons with IDs #add and #remove.

 $().ready(function() {  
     $('#add').click(function() {  
        return !$('#select1 option:selected').remove().appendTo('#select2');  
     });  
     $('#remove').click(function() {  
        return !$('#select2 option:selected').remove().appendTo('#select1');  
     });  
 });
0
Andreas On

This is how i ended up doing it

Multiple.Move = function (from, to)
{
    $('#' + from + ' option:selected').remove().appendTo('#' + to);
}

And some html for the buttons and the select.

<select multiple="multiple" id="available">
    <option value="1">BMW</option>  
    <option value="1">Volvo</option>  
    <option value="1">Audi</option>  
    <option value="1">Saab</option>
</select>  
<input type="button" value="Add" onclick="Multiple.Move('available', 'selected')" />
<input type="button" value="Remove" onclick="Multiple.Move('selected', 'available')" />
<select multiple="multiple" id="available">
</select>