A drop-down list box and a menu list box have the same basic syntax. The drop-down list box and menu list box are widely used in website programming. You can select conditions through the drop-down list box and menu list box. A drop-down list box and a menu list box have the same basic syntax. The drop-down list box and menu list box are widely used in website programming. You can select conditions through the drop-down list box and menu list box.
1. get the value of the drop-down list box
The method for getting the value of the drop-down list box is very simple. similar to getting the value of the text box, you must first define the name attribute value of the drop-down list box, and then apply the $ _ POST [] global variable to get the value.
The following example shows how to obtain the value of the drop-down list box. This instance selects the conditions specified by the user in the drop-down list box and click submit to output the selected condition values. The procedure is as follows:
(1) create an index. php page, create a form, and add a drop-down list box and a submit button. the main code is as follows:
form
Note: in the code of this instanceSet the size attribute in the tag. The value of the size attribute is 1, which indicates the drop-down list box. if the value is greater than 1, it indicates the list box. the number of elements in the list is determined based on the size of the specified value. If the number of elements in the list is greater than the value set by the size attribute, a vertical scroll bar is automatically added.(2) compile a PHP statement, use $ _ POST [] global variables to obtain the value of the drop-down list box, and use echo statement output. The PHP code is shown as follows: (3) enter the running address in the browser and press enter to obtain the running result as shown in:2. get the value of the menu list boxWhenIf the multiple attribute is set in the tag, it is the menu list box. you can select multiple conditions. Because the menu list box usually contains multiple values at the same time, to facilitate value transfer,Mark naming is usually in the form of an array. the code format is as follows:
Return to the page, you can use the count () function to calculate the size of the array and use the for loop statement to output the selected menu item.
Set a menu list box for users to select their favorite books. click submit to output the selected condition values. The procedure is as follows:
(1) create a new index. php dynamic page, create a form, and add a menu list boxTo add a submit button for the array variable named "select. The main code is as follows: FormNote: the code for this instance is inSet the multiple attribute in the tag. Therefore, the value of the size attribute should beThe total number of tags is a one-to-one relationship.
(2) compile a PHP statement, use $ _ POST [] global variable to obtain the value of the menu list box, and use echo statement output. The PHP code is shown as follows:
(3) enter the running address in the browser and press enter to obtain the running result as shown in:
Tip: you can press Shift or Ctrl and click to select multiple menu items.
The above is the detailed content for php to get the value of the form list box. For more information, see other related articles in the first PHP community!