linuxStat PHP Documentation

Collection of data from a drop-down list box in a form

A drop-down list box is used to select one option from multiple options.
It has the following appearance in a web form.

Select country of interest:




The user clicks on the arrow and a list of coutry names drops down.
Hence this form element is called a drop-down list box.
The user selects one country by clicking on it then
she presses the Submit button.


An HTML document containing the above drop-down list box is the following.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<title>Executed on Dell Server, Intel Processor, created on HP laptop</title>
</head>
<body bgcolor="#0F243E" text="#FFFF00" lang=EN-US>
<form action="getcountryofinterest.php" method="get">
Select country of interest:<br><br>
<select name="country">
<option value="United States">USA<br>
<option value="Japan">Japan<br>
<option value="United Kingdom">UK<br>
<option value="Germany">Germany<br>
<option value="France">France<br>
</select> <br><br>
<input type="submit" name="Submit" value="Submit" size="30">
</form>
</body>
</html>

When the user presses the Submit button, the PHP code interpreter
executes a PHP program contained in the file getcountryofinterest.php.
Before the PHP program in getcountryofinterest.php is executed,
a map called _GET is constructed. The value corresponding to the selection
made by the user is given in the _GET map. Thus,
$_GET["country"]
will give the value corresponding to the selection made by the user.

We will construct a PHP program that will echo back the selection made
by the user as follows and save it in getcountryofinterest.php file.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<title>Executed on Dell Server, Intel Processor, created on HP laptop</title>
</head>
<body bgcolor="#0F243E" text="#FFFF00" lang=EN-US>
<?php
# Example of check box data in _GET map
print "Your country of interest is: {$_GET["country"]} <br>";
?>
</body>
</html>


Click the following link to execute the above PHP code
by my server's PHP interpreter.

Try the above example   Next   Index