$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
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.
Surya | 29-12-2014 |
Thanks.it very useful and userfriendly. |
monika | 27-09-2018 |
your code is very nice and easy to understand thanks |