I am trying to submit this multi select as an array but when I submit it nothing prints to the screen so what am I doing wrong?
HTML
<div class="container">
<select name="itemsToChoose" id="left" size="8" multiple="multiple">
<option value="1">item1</option>
<option value="2">item2</option>
<option value="3">item3</option>
<option value="4">item4</option>
<option value="5">item5</option>
</select>
</div>
<div class="low container">
<input name="left2right" value="add" type="button">
<input name="right2left" value="remove" type="button">
</div>
<form Method ="POST" action="multiSelectRead.php">
<div class="container">
<select name="itemsToAdd" id="right" size="8" multiple="multiple">
</select>
</div>
<input type="submit" style="width: 75px; border: 1px solid gray" value="Submit">
<br />
</form>
The JS code:
$(function() {
$(".low input[type='button']").click(function() {
var arr = $(this).attr("name").split("2");
var from = arr[0];
var to = arr[1];
$("#" + from + " option:selected").each(function() {
$("#" + to).append($(this).clone());
$(this).remove();
});
});
})
$('form').submit(function() {
$('#seldist option').each(function(i) {
$(this).attr("selected", "selected");
});
});
multiSelectRead.php
<?php
print_r($_POST["itemsToAdd"]);
?>
The user is suppose to add values then hit submit. But I tried it and yet it wont pass the itemstoAdd values in array to php….
Here is snippet: http://jsfiddle.net/an4gA/
In the jsFiddle you posted, your jQuery code to select the options reads:
Thing is, your select box’s ID is “right”.
Either change the
#seldistabove to#right, or change your select box’s ID to “seldist”.