<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>PHP Dropdown menu</title>
</head>
<body>
<?php
function form($item)
{
if (isset($_POST['submit']))
{
if ($item == 'item1')
{
echo 'selected';
} elseif ($item == 'item2')
{
echo 'selected';
} elseif ($item == 'item3')
{
echo 'selected';
} elseif ($item == 'item4')
{
echo 'selected';
} elseif ($item == 'item5')
{
echo 'selected';
}
}
}
$item = $_POST['item'];
switch ($item)
{
case 'item1':
$message = 'You had choosen <b>item1</b> and the cost price is <b>$1,000</b>';
break;
case 'item2':
$message = 'You had choosen <b>item2</b> and the cost price is <b>$2,000</b>';
break;
case 'item3':
$message = 'You had choosen <b>item3</b> and the cost price is <b>$3,000</b>';
break;
case 'item4':
$message = 'You had choosen <b>item4</b> and the cost price is <b>$4,000</b>';
break;
case 'item5':
$message = 'You had choosen <b>item5</b> and the cost price is <b>$5,000</b>';
break;
default:
$message = 'To see the price of an item, please choose the item in the drop down menu and hit the submit button.';
break;
}
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select size="1" name="item">
<option value="item1" <?php form($_POST['item']); ?>>item1</option>
<option value="item2" <?php form($_POST['item']); ?>>item2</option>
<option value="item3" <?php form($_POST['item']); ?>>item3</option>
<option value="item4" <?php form($_POST['item']); ?>>item4</option>
<option value="item5" <?php form($_POST['item']); ?>>item5</option>
</select><input type="submit" value="Submit" name="submit">
</form>
<?php echo $message; ?>
</body>
</html>