HTML Code Tutorial

Tutor Ebook Download

Forms and Selection Boxes

Selection boxes add a little elegance to the structure of a form. They simply allow a user to make selections from a predefined list.

The Tags:

Select <select></select>

Attributes

  • name (required) supplies the name for the name/value pair.
  • size determines the number of options to be displayed at one time. Default=1.
  • multiple allows mutiple selections. (Control Key depressed)

Option <option></option>

Note: Closing option tag is not required.

Attributes

  • selected used to set default option.
  • value option text is default.

A simple form:

What states have you visited?

For multiple selections Hold Down the Control Key

The Form Code

<form method="post" action="script name">
What states have you visited?<br>
<select name="state[]" size="7" multiple>
<option> Alabama
<option>Arkansas
<option>Colorado
<option>Kentucky
<option>Tennessee
<option>Washington
<option>None of the above.
</select>
<input type="submit">
</form>

Note: Most people don't know how to make multiple selections using a selection box. Include the instruction for holding down the Control Key on your form.

PHP Script

<html>
<head><title></title></head>
<body>
<?
print "<h1>You have visted:</h1>";
foreach ($state as $value){
print "$value<br>";
}
print "<br>";
print "<a href=formselections.htm>Back to Tutorial</a>";
?>
</body>
</html>

Take a quiz. Take a Quiz on this Information.



CGI Online
How to Create a Website -Tutorial
Main Website


This Free HTML Tutorial
is provided by Net Success 2000 Plus Inc.
PO Box 1508
Somerset, KY 42502
Last Modified: September 3, 2007

HTML Codes Tutor Ebook