how to use a combo box in php - Select combo box is a box-shaped form elements which when clicked will display a drop-down menu option (drop down list). The combo box is more efficient when a relatively large selection of options. With the combo box will form more compact because it only takes one line area just like the input checkbox. The process of choosing the combo box is done by first showing the entire contents by clicking kllik combo box and select by clicking one of the contents of the combo box list.
How to create a combo box select the form
Different from the previous form elements that use the <input> without cover, when to make a combo box using the <select> and closed with the tag </ select>. To create a table of contents of the combo box using the <option> and the closing tag </ option>.
To define the name of the combo box using the name attribute is placed in the <select>. And to define the value / value of an option is the choice of using the value attribute is placed in the <option>. If you want one of the options in the select-load when you first use the selected attribute in the <option>.
The actual number of options in the combo box that can be done at least two options, but the use of dynamic combo box that mengkin only bring one option only, the option in the combo box can be made one. For the maximum number of options in the combo box yet I know, but it is recommended not to make too many options so as not to confuse users.
The use of the combo box select
As mentioned above that the combo box select is used to select one option from several options on the form. Reasons to use a combo box rather than a radio button input is to place efficiency if the options that appear relatively much.
Examples of the use of the combo box is when we choose the country of origin when the registration process. There is another example of the use of such a dynamic combo box when selecting provinces and districts on the Commission's website when we checked our names on the electoral DPT yesterday. There is little difference between the combo box that is used on a PHP form with a combo box in visual basic that can not type text in the combo box. If you want that it should use self-made components.
Determining the value of the combo box select
Value combo box is determined by the value attribute on the <option>. Value combo box in the form of strings and in writing must be enclosed in quotes. One reason to use the combo box are the values to be entered by the user is already known, so the user is not a typo in entering data.
Taking the value of the combo box select
How to retrieve the value of the combo box as when taking the value of the input text. Option is selected automatically becomes a return value of a combo box. When the combo box is loaded automatically selects the option written on unless the other option is determined by the selected attribute.
Examples of the use of the combo box select the PHP
Make combo box select the form<form action="" method="post">
<select name="fruit"> <option value="">Silahkan Pilih</option> <option value="fruit1">Apel</option> <option value="fruit2">Jeruk</option> <option value="fruit3">Semangka</option> <option value="fruit4">Salak</option> </select> input type="submit" name="enter" value="Enter"> </form>
Display form above the browser
<form name="form1" method="post" action=""> <label> <select name="select" tabindex="4" id="select" > <option>fruit1</option> <option>fruit2</option> <option>fruit3</option> <option>fruit4</option> </select> </label> <label> <input type="submit" name="Submit" value="Enter"> </label> </form>
Silahkan Pilih Apel Jeruk Semangka Salak
Create a script to handle combo box
<?php if(isset($_POST['enter'])) { if(emptyempty($_POST['fruit'])) { echo " You have not selected!"; } else echo "Selected : ".$_POST['fruit']; } ?>
explanation script
On the form there is a combo box with the attribute name = fruit. In the combo box list, there are four names of fruit and a selection of free choice placed at the top of the label "Please select". The purpose of this selection is empty prevent data retrieval if the user has not chosen at once notice to allow choosing. Each option has a value and a different label, ie Apples, Oranges, Watermelon and Salak.
To retrieve the value of the combo box select to use way while taking the value of the input text. Value generated by the combo box is the value of the option chosen. In the script was made after the detection of the enter key is pressed will check the value of the combo box select fruit. If the value is blank (empty) means select combo box has not been (still appear "Please select"). And if the value is not empty will display the value of the combo box select.
Referensi :
0 komentar:
Posting Komentar