$color=$_POST['color'];
or
$color=$_GET['color'];
Based on the form method ( GET or POST ) we can get or collect the option selected and store them in variable $color.
| Press and hold the Ctrl key and then click on the options to select multiple. |
<form method=post action=''>
<select name='color[]' size=4 multiple>
<option value='blue'>Blue</option>
<option value='green'>Green</option>
<option value='red'>Red</option>
<option value='yellow'>Yelllow</option>
<option value='' selected>Select a Color </option>
<option value='white'>White</option>
</select>
<input type=submit></form>
///// collecting form data /////
@$color= $_POST['color'];
if( is_array($color)){
while (list ($key, $val) = each ($color)) {
echo "$val <br>";
}
}//
else{echo "not array";}
if( !empty($color[0]) ){
////
// Your code here
///
}
Managing Multiple selection list box using JQuery
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| Surya | 29-12-2014 |
| Thanks.it very useful and userfriendly. | |
| monika | 27-09-2018 |
| your code is very nice and easy to understand thanks | |