Entry
How can I find out which option a user selected in a SELECT form?
Jul 8th, 1999 21:46
Nathan Wallace, Troels Arvin
Try playing around with this script to see how things work:
<html><head><title>Option test</title></head>
<body>
<form action="<?php print $PHP_SELF ?>">
<select name="var"> <!-- Note: Variable name defined here -->
<option value="">Please select</option>
<option>a</option>
<option>b</option>
<option>c</option>
</select>
<input type="submit" name="submit">
</form>
<?php
// If the user did not submit the form then output no more
if ($submit) {
print "<hr>Value of <code>var</code>: ";
if (empty($var))
print "(empty)";
else
print $var;
}
?>
</body></html>