July 25th, 2013, 11:33 PM
Trouble with JQuery multiple select
I'm having trouble with a JQuery multiple select.
I have the following code which allows the user to select items from one list (select1) by adding them to another list (select2):
The selection method works great and values in "select1" move to "select2" when the "add" link is clicked.
<select multiple id="select1" name="select1">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
<a href="#" id="add">add >></a>
<select multiple id="select2" name="select2"></select>
<a href="#" id="remove"><< remove</a>
<INPUT TYPE='submit' NAME='lesson_submit' VALUE='Save Changes'>
In theory, the values added to "select2" should be available in an array, so I am trying to print them to the browser as such:
However, the only thing that is printed is the first "begin output" statement.
echo "begin output:<br>";
$array = $_POST['select1'] ;
foreach($array AS $s)
"$value = $s " ;
echo "Value: $value<br>";
echo "end output:<br>";
Can anyone see what I am doing wrong?
July 26th, 2013, 12:58 AM
you're trying to print the first one rather than the second, for one thing.
print_r($_POST) and see what's in there.
There's no code anywhere in here that actually handles moving the items between the lists. Perhaps that code is wrong, wherever it is.
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question
or you're a Help Vampire.
Trying to argue intelligently? Please read this.
July 26th, 2013, 12:59 AM
Also your SELECTs have to be named with s.
<select multiple id="select2" name="select2">
July 26th, 2013, 10:15 AM
Thanks for your help...
I now have the following code:
which produces the following results:
foreach($_POST['select2'] AS $s)
echo "$nbsp   Value: $s<br>";
echo " -- end output --<br>";
The main problem was actually that my value assignment in the original code ("$value = $s " ; ) had quotes around it... I just didn't see that... duh!
Works great now
Thanks again for your input.