I have a HTML form with two select elements(listboxes) and two buttons to move the data from one listbox to another(using JavaScript):
<form action="page.php" method="post">
<select name="select1" multiple="yes">
<option value="1">Left1</option>
<option value="2">Left2</option>
<option value="3">Left3</option>
</select>
<input type="button" value="-->" onclick="moveOptions(this.form.select1, this.form.select2);" /><br />
<input type="button" value="<--" onclick="moveOptions(this.form.select2, this.form.select1);" />
<select name="select2" multiple="yes">
<option value="4">Right1</option>
<option value="5">Right2</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>
When I hit the Submit button I want to get all the values stored in the listboxes.
foreach ($_POST['select1'] as $value)
{
//save data to database
}
This just gets one selected value(if there was one).
I managed to get multiple values (if they are selected) by putting a []
after the name of the select
.
<select name="select1[]" multiple="yes">
But this still doesn't gets the unselected values, and this way the data moving JavaScript function doesn't works either.