0
Select tag with switch case in php
Give some ex for switch case that post answer from select tag.
1 Antwort
+ 4
<?php
// These are for testing in Code Playground
// Comment lines between [BEGIN] and [END]
// for running outside Code Playground.
// You can change the value of
// $_POST["favFruit"] to any selection during
// testing in Code Playground. It is not
// necessary to do outside Code Playground.
// [BEGIN]
$_POST ["Submit"] = "Submit";
$_POST["favFruit"] = "Apple";
// [END]
if($_POST["Submit"])
{
$select = $_POST["favFruit"];
switch ($select)
{
case "Apple":
$val = "You like $select #1";
break;
case "Orange":
$val = "You like $select #2";
break;
case "Water Melon":
$val = "You like $select #3";
break;
case "Grapes":
$val = "You like $select #4";
break;
}
}
?>
<!DOCTYPE html>
<html>
<head><title>Favorite fruit</title>
</head>
<body>
<form action="" method="post">
<label for="favFruit"> Pick your favorite fruit</label>
<select name="favFruit" id="favFruit">
<option value="">Choose your favorite</option>
<option value="Apple">Apple</option>
<option value="Orange">Orange</option>
<option value="Water Melon">Water Melon</option>
<option value="Grapes">Grapes</option> </select>
<input type="submit" name="submit" value="Submit">
<p><?php echo $val;?></p>
</form>
</body>
</html>
Hth, cmiiw
#savepalestine