Get select option and radio button value in php
HTML Dropdown allow user to select one or multiple option from given dropdown options..in this lesson we will learn how to read or get html select option value using php.
html select multiple options php |
<html> <head> <title>Get option Value in PHP</title> </head> <form method="POST" action=""> <select name="company"> <option value="Google Inc">Google Inc</option> <option value="Yahoo Inc">Yahoo Inc</option> <option value="Amazon Inc">Amazon Inc</option> <option value="Infosys Inc">Infosys Inc</option> <option value="Reliance Inc">Reliance Inc</option> <option value="LG Inc">LG Inc</option> </select> <input type="submit" name="submit" value="Click To Process"/> </form> </html> <?php if(isset($_POST['submit'])){ if(!empty($_POST['company'])){ $company=$_POST['company']; echo '<b>'.$company.'</b>'; } } ?>Your Result will be look like below:
HTML option select value in php |
use Ctrl+right click to select multiple options..
<html> <head> <title>Get option Value in PHP</title> <style> #option{ height:200px; width:200px; } option{ padding:2px; color:red; font-size:16px; font-style:italic; } </style> </head> <form method="POST" action=""> <table> <th>To Select Multiple Options Press ctrl+right click :</th> <tr> <td> <select id="option" multiple name="company[]"> <option value="Google Inc">Google Inc</option> <option value="Yahoo Inc">Yahoo Inc</option> <option value="Amazon Inc">Amazon Inc</option> <option value="Infosys Inc">Infosys Inc</option> <option value="Reliance Inc">Reliance Inc</option> <option value="LG Inc">LG Inc</option> <option value="Samsung Inc">Samsung Inc</option> <option value="Apple Inc">Apple Inc</option> <option value="Nokia Inc">Nokia Inc</option> <option value="Sony Inc">Sony Inc</option> <option value="Beidu Inc">Beidu Inc</option> </select> </td> </tr> <tr> <td><input type="submit" name="submit" value="Click To Process"/></td> </tr> </table> </form> </html> <?php if(isset($_POST['submit'])){ if(!empty($_POST['company'])) { $company=$_POST['company']; echo "<div>You have selected :</div>"; foreach ($company as $row) { echo "<div><b>".$row."</b></div>"; } }else{ echo "You Have not Select any company"; } } ?>Result:
html select multiple options php |
<html> <head> <title>Get Radio Button Value in PHP</title> </head> <h3>HTML Radio Button Value in php</h3> <form method="POST" action=""> <table> <tr> <td><input type="radio" name="radioname" value="Google Inc"/>Google Inc</td> </tr> <tr> <td><input type="radio" name="radioname" value="Facebook Inc"/>Facebook Inc</td> </tr> <tr> <td><input type="radio" name="radioname" value="Yahoo Inc"/>Yahoo Inc</td> </tr> <tr> <td><input type="radio" name="radioname" value="Microsoft Inc"/>Microsoft Inc</td> </tr> <tr> <td><input type="submit" name="submit" value="Click To Process"/></td> </tr> </table> </form> </html> <?php if(isset($_POST['submit'])){ if(!empty($_POST['radioname'])){ $radioname=$_POST['radioname']; echo 'You have Selected <b>'.$radioname.'</b>'; }else{ echo 'You Have not Select Value'; } } ?>
Result:
php radio button value |
Thank you for visiting...
No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.