The drop down box allows you to select one or more values from it. The HTML tag "select" is also known as "drop down" or "pul down" box.You can get value from drop down box using PHP while form submitting.
HTML form with drop down box
The below example describes how to create HTML form with drop down box.
<html>
<body>
<form action="#" method="post">
<select name="country">
<option value="USA">USA</option>
<option value="United Kingdom">United Kingdom</option>
<option value="France">France</option>
<option value="Russia">Russia</option>
<option value="India">India</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<body>
<form action="#" method="post">
<select name="country">
<option value="USA">USA</option>
<option value="United Kingdom">United Kingdom</option>
<option value="France">France</option>
<option value="Russia">Russia</option>
<option value="India">India</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Retrieve input data from drop down box using PHP
You can retrieve input data from drop down box using following types in PHP.
$_POST['drop_down_name'] (if method is post)
$_GET['drop_down_name'] (if method is gett)
$_REQUEST['drop_down_name'] (if method is either post or get)
The following PHP script describes how to retrieve input data from drop down box while form submitting.
<html>
<body>
<form action="#" method="post">
<select name="country">
<option value="USA">USA</option>
<option value="United Kingdom">United Kingdom</option>
<option value="France">France</option>
<option value="Russia">Russia</option>
<option value="India">India</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST['submit']))
{
$country=$_POST['country'];
echo'You selected '.$country;
}
?>
</body>
</html>
<body>
<form action="#" method="post">
<select name="country">
<option value="USA">USA</option>
<option value="United Kingdom">United Kingdom</option>
<option value="France">France</option>
<option value="Russia">Russia</option>
<option value="India">India</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST['submit']))
{
$country=$_POST['country'];
echo'You selected '.$country;
}
?>
</body>
</html>
While submitting form with select country from drop down box, you can get selected country as output.
Related Post:
Related Post:
No comments:
Post a Comment