Multiple Selection in HTML Dropdown with help of PHP Code
×


PHP Multiple Selection

9403

To select multiple values as a dropdown, 'Foreach LOOP' is used. Now you can easily multiple selection in html dropdown with the help of PHP (Hyper Text PreProcessor Language)

For Example:

<?php
if(isset($_POST['subject']))
{
$subject_array=$_POST['subject'];
$i=0;
foreach($subject_array as $key=> $value)
{
$i++;
echo "You choosed <b>" . $value . " </b> . <br>";
}
}
?>

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title> Multiple Selection </title>
</head>

<body>
<h2> Choose your subject</h2> (Hold "ctrl" key to select multiple values)
<br>
<form action="" method="post" >
<select name="subject[]" multiple>
<option value="Hindi"> Hindi </option>
<option value="English"> English </option>
<option value="Mathematics"> Mathematics </option>
<option value="Physics"> Physics </option>
<option value="Chemistry"> Chemistry </option>
<option value="Biology"> Biology </option>
<option value="Sanskrit"> Sanskrit </option>
</select>
<br>
<input type="submit" name="sub" value="Submit">
</form>

</body>

</html>




Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments