I have two HTML selects in a form. The first is called available
and contains several options:
Try this one UPDATED!
HTML
<select name="sortedby" multiple="multiple" id="sortedby" onchange="putvalue()">
<option value="start">Start time</option>
<option value="thread_id">Thread Id</option>
<option value="user_name">Username</option>
</select>
<select name="sortedby_target" id="sortedby_target" multiple="multiple" ></select>
SCRIPT
function putvalue(){
$('option[value="' + $('#sortedby_target').val() + '"]').prop('selected','');
$("#sortedby_target").append('<option value="' + $('#sortedby').val() + '" selected>' + $('#sortedby').val() + '</option>');
$("#sortedby option[value=" + $('#sortedby').val() + "]").remove();
}
I apologized for my first solution hopefully this helps.
If you want to be selected all the selected items, remove this line
$('option[value="' + $('#sortedby_target').val() + '"]').prop('selected','');
<form name="jmxForm" onsubmit="selectAllOptions(sortedby_target)">
....
</form>
function selectAllOptions(obj) {
if (!hasOptions(obj)) { return; }
for (var i=0; i<obj.options.length; i++) {
obj.options[i].selected = true;
}
}
<input type="submit" onclick="selectAllOptions(sortedby_target);" />
or
<form onsubmit="selectAllOptions(sortedby_target);"></form>
You can get inspired here: http://demo.redmine.org/projects/asdf/issues when trying to change columns in a table.