Page 1 of 1
How to get all elements of a dropdown list into a variable o
Posted: Sun Jan 16, 2011 11:55 pm
by hmdnawaz
I have a dropdown list which have some elements.
I want to get all the elements of the dropdown list into a variable of type array.
Any Idea???
Re: How to get all elements of a dropdown list into a variab
Posted: Mon Jan 17, 2011 12:01 am
by social_experiment
The square brackets indicate that the values from the select element will be available as an array
Code: Select all
<select name="listOfItems[]">
<option value="1">One</option>
<option value="2">Two</option>
</select>
To access the values
Code: Select all
<?php
if (is_array($_POST['listOfItems'])) {
foreach ($_POST['listOfItems'] as $value) {
echo $value;
}
}
?>