How to Get Selected Item From Combobox in PHP

How to get selected item from combobox in php - If in the form input type check box, the user is possible choose more than one option. So in the input type combo box, the user is only possible choose one option from several options. In order to better understand the following I give examples of its application in a program.
Program 1
File Name: input08.php
Description: The program displays the form inputan favorite cartoon movies with combo box.
Open notepad then enter the following html code.
<html>
 <head><title>Favorite Cartoon Movie ~ Input Combo Boxes</title></head>
<body>
  <FORM ACTION="proses08.php" METHOD="POST" NAME="input">
   <h2>Choose Your Favorite Cartoon Movie :</h2>
<select name="cartoon">
 <option value="Sponge Bob">Sponge Bob</option>
 <option value="Sinchan">Sinchan</option>
 <option value="Conan">Conan</option>
 <option value="Doraemon">Doraemon</option>
 <option value="Dragon Ball">Dragon Ball</option>
 <option value="Naruto">Naruto</option>
</select>
   <input type="submit" name="choose" value="choose">
</FORM>
</body>
</html>

How to Get Selected Item From Combobox in PHP

Save the php code into the htdocs folder named input08.php.
Program 2
File Name: process08.php
Description: Program to display the name of favorite cartoon movies according to the input in program 1.
Enter the following php code into the notepad.
<?php
if (isset($_POST['choose'])) {
$film = $_POST['cartoon'];
 echo "Your Favorite Cartoon Movie is :
  <font color=blue><b>$film</b></font>";
}
?>

How to Get Selected Item From Combobox in PHP

Save the php code into the htdocs folder named process08.php.
Explanation of Programs 1 and 2 (How to Get Selected Item From Combobox in PHP)
Program 1 will display the preferred form of combo box combo box input box (see picture). To create an input type combo box, can use the tag <select> and <option>. In the input form type check box, name is placed on the <select> tag. Users can only select one option from a number of options that are displayed in the form of a drop down list. View image. To retrieve value (value) from combo box type form, can directly access it according to its name. Watch the 2nd row program!.
To see the result, open the browser then in the address bar type http://localhost/input08.php, then the result will look like the following.
How to Get Selected Item From Combobox in PHP
Program View

How to Get Selected Item From Combobox in PHP
Program View

That is the tutorial on how to get selected items from combobox in php, hopefully can be understood and can improve our ability to learn php programming language.

Comments