I have two muti-selects where I can tranfer items back-and-forth, which is working perfect in all browsers. My problem is in IE9 the .each()
does not seem to be running. Basically what I'm doing is running an .each()
that will select all items in the desired multi-select before I submit. In IE9 when I click submit none of the items in select2
never get selected.
JQUERY
/* multi-select handler */
$('#add').click(function()
{
return !$('#select1 option:selected').remove().appendTo('#select2').removeAttr("selected");
});
$('#remove').click(function()
{
return !$('#select2 option:selected').remove().appendTo('#select1').removeAttr("selected");
});
/* submit button handler */
$('#submit').click(function)
{
/* select all items in select2 */
$('#select2 option').each(function()
{
$(this).attr("selected","selected");
});
/* check to see if any items were selected */
if( $('#select2 option').length === 0 )
{
alert('no items selected');
}
else
{
alert('success');
}
});
HTML
<div class="multi-select-container">
<div class="multi-select-left">
<select multiple id="select1">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
<option value="6">Six</option>
</select>
</div>
<div class="multi-select-center">
<button id="add" class="btn btn-mini btn-add" style="display:block;margin:5px;">Add</button>
<button id="remove" class="btn btn-mini btn-delete" style="display:block;margin:5px;">Remove</button>
</div>
<div class="multi-select-right">
<select multiple id="select2"></select>
</div>
</div>