faqts : Computers : Programming : Languages : PHP : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 9 people (78%) answered Yes
Recently 7 of 9 people (78%) answered Yes

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"