Link to home
Start Free TrialLog in
Avatar of vinitha
vinitha

asked on

Value from a Multiple Select

Hi,

how can get the values from a select having multiple items selected.
<select name="t" multiple>
<option value=1>name1</option>
<option value=2>name2</option>
<option value=3>name3</option>
<option value=4>name4</option>
</select>

when i try to post the form the $_post['t']  returns only the last index e.g if name2 and name3 are selected ; only name3 is  returned.

help asap.

regards,

vinitha
Avatar of aishcash
aishcash
Flag of India image

Just make ur select variable an array to receive the multiple values. Like this <select name="t[]" multiple>

now when u will post the form u will get all the selected values in this array, which u can access it like this

echo $t[0]; //value selected 1
echo $t[1]; //value selected 2
echo $t[2]; //value selected 3

This works as I have checked.
------------------------------------
<select name="t[]" multiple>
<option value=1>name1</option>
<option value=2>name2</option>
<option value=3>name3</option>
<option value=4>name4</option>
</select>

--------------------------------------

Hope this will solve your problem
ASKER CERTIFIED SOLUTION
Avatar of ferhad
ferhad
Flag of Azerbaijan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial