The list box has two forms, the drop-down list box and the menu list box, and their basic syntax is the same. Drop-down list boxes and menu list boxes are widely used when designing a Web site. You can use the drop-down list box and the menu list box to implement the selection of conditions.
1. Get the value of the drop-down list box
The way to get the value of a drop-down list box is very simple, similar to getting the value of a text box, you first need to define the Name property value of the drop-down list box, and then apply the $_post[] global variable to get the value.
The following is an example to get the value of the drop-down list box, which is to select the user-specified condition in the drop-down column box, click the "Submit" button to output the user selected criteria value. The specific steps are shown below:
(1) Create a new index.php page that creates a form form, adds a drop-down list box, and a Submit button whose main code is as follows:
<! DOCTYPE html>
Note: In the code for this instance, the Size property is set in the <select> tag, the value of the Size property is 1, which is the drop-down list box, and if the value is greater than 1, it is represented as a list box to specify the size of the value to determine the number of elements in the display list. If the number of elements in the list is greater than the value set by the Size property, the vertical scroll bar is added automatically.
(2) write the PHP statement, through the $_post[] global variable to get the value of the drop-down list box, using the Echo statement output. Its PHP code is shown below:
<?php if ($_post["select"]!= "") { //Response form event, returns the value of the multi-select list box echo "The department you selected is:". $_post["select"];}? >
(3) Enter the running address in the browser and press ENTER to get the result as shown:
2. Get the value of the menu list box
When the multiple property is set in the <select> tag, the menu list box allows you to select multiple criteria. Because the menu list box is generally multiple values at the same time, in order to facilitate the value of the,<select> tag name is usually in the form of an array, the code format is as follows:
<input type= "checkbox" Name= "checkbox[]" multiple>
The return page can use the count () function to calculate the size of the array, combined with a For loop statement to output the selected menu item.
Set a menu list box for users to select their favorite books, click the Submit button, and output the selected criteria values. The specific steps are as follows:
(1) Create a new index.php dynamic page, create a form form, add a menu list box <select>, an array variable named "select[]", and add a Submit button. Its main code is as follows:
<! DOCTYPE html><?php if ($_post[' Submit ']== "commit") { //Use the IF condition statement to determine if the form was submitted echo "selected programming book:"; for ($i =0; $i <count ($_post[' select "), $i + +) { echo $_post[' select '] [$i]." "; For loop output string and menu list box value }}?>
(3) Enter the running address in the browser and press ENTER to get the result as shown:
Tip: Friends can choose to select multiple menu items by holding down the SHIFT key or the CTRL key and clicking on them.