Creating Form Elements with Multiple Options : Form Select « Form « PHP






Creating Form Elements with Multiple Options

 
<html>
<body> 
<?php
if ($_POST ['submitted'] == "yes") {
  if (count ( $_POST ['fruit'] ) != 0) {
    echo "Your Selections:<br />";
  } else {
    echo "You have not made any selections.<br /><br />";
  }
  for($i = 0; $i < count ( $_POST ['fruit'] ); $i ++) {
    echo $_POST ['fruit'] [$i] . "<br />";
  }
  ?><a href="index.php">Try Again</a><?php
}
if ($_POST ['submitted'] != "yes") {
?> 
<form action="index.php" method="post">
<input type="hidden" name="submitted" value="yes" /> Your Choice (s): <br />
<select name="fruit[]" multiple="multiple">
  <option value="Bananas">Bananas</option>
  <option value="Apples">Apples</option>
  <option value="Oranges">Oranges</option>
</select><br />
<input type="submit" value="Submit" /></form> 
<?php
}
?> 
</body>
</html>
  
  








Related examples in the same category

1.Form select input
2.An HTML Form Including a SELECT Element
3.A
4.A day choice
5.An HTML Form with a select Element
6.Validating a drop-down menu with in_array()
7.Displaying a
8.Generating a dynamic pull-down menu
9.Setting a default value in a
10.Setting defaults in a multi-valued
11.Creating Form Elements Based on the Current Time and/or Date
12.One choice for each day from 1 to 31
13.One choice for each year from last year to five years from now