There are drop-down list box list boxes and menus list box in two forms, their basic syntax are the same. During the website design program, the drop-down list boxes and menus list box applications are very broad. Can be achieved by selection of the conditions of the drop-down list boxes and menus list box.
1. Get the value of the drop-down list box
Gets the value of the drop-down list box method is very simple, similar to get the value of a text box, you first need to define the name property value drop-down list box, and then use $ _POST [] to get the value of global variables. Marble repair factory mechanical member
Here, an example to explain the drop-down list box to get the value of this example is to select a user-specified conditions in the drop-down list box, click on the "submit" button, the value of the output condition selected by the user. Specific steps shown below:
(1) Create a index.php page, create a form form, add a drop-down list box and a submit button, the main code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
Note: In the present example the code, provided the size attribute, the size attribute in the <select> tag value is 1, the drop-down list box; if the value is greater than 1, it indicates that the list box, it is determined to display the size of the specified value the number of elements in the list. If the number of elements in the list greater than the value of the size attribute set, the vertical scroll bar is added automatically.
(2) write PHP statements, by $ _POST [] global variable to get the value of the drop-down list box, use echo statements output. PHP code which is shown below:
1 2 3 4 5 |
|
(3) enter the run in the browser address, and press Enter to obtain the results shown below of the operation:
2. Get the value menu list box
When <select> tag set multiple properties, compared with the list box menu, you can select a plurality of conditions. Since the menu list box are generally a plurality of values exist, for convenience of traditional values, <select> tag is usually named an array, the code format is as follows:
1 |
|
You can then return the page count () function to calculate the size of the array, binding loop output for the selected menu item.
Setting a menu list box for users to choose favorite books, click the "submit" button, select the output condition value. Specific steps are as follows:
(1)新创建一个 index.php 动态页,创建一个 form 表单,添加一个菜单列表框<select>,命名为“select[]” 的数组变量,添加一个提交按钮。其主要的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
注意: 本实例的代码在<select>标记中设置 multiple 属性,因此,size 属性的值应与<option>标记的总数是一一对应的关系。
(2)编写PHP语句,通过$_POST[]全局变量来获取菜单列表框的值,使用echo语句输出。其PHP代码如下显示:
1 2 3 4 5 6 7 8 |
|
(3)在浏览器中输入运行地址,按回车键,