Entry
How to extract multiple option value selected in <SELECT>
Dec 21st, 2006 11:37
John Dubya, Prasanth Jose, www.google.com
<SELECT id="mm" multiple size="20"
name="mm[]"
multiple >
And now to extract this value in mm[] i.e selected values,
after post we can extract these value like-
if (isset($_POST['submit']))
{
$countmm = count($_POST['mm']);
$ar = $_POST['mm'];
}
You can also use implode() to extract values from a select group.
Let's say you have a select group that looks like this:
<select name="fontdecoration[]" multiple>
<option value="bold">Bold</option>
<option value="italic">Italic</option>
</select>
Then, in your PHP code, use this:
implode(" ", $_POST['fontdecoration'])
The first part (" ") is what will be used to separate the values in
the POSTed variable. The second part is what array will be imploded
upon parsing. So, if both "bold" and "italic" are selected, this
implode function will print out:
"bold italic"