PHP HTML Dynamic Drop Down List From Ajax
From w3cyberlearnings
Contents |
PHP Dynamic Drop Down uses Ajax
Generate HTML select option uses Ajax.
Example 1
page.html
<html> <head> <title>Dropdown</title> <script type="text/javascript" src="jquery.min.js"> </script> <script type="text/javascript"> $(document).ready(function() { $('div#car_list').load('car.php'); }); </script> </head> <body> <form> <div id="car_list"></div> </form> </body> </html>
car.php
<?php $array = array('BMW', 'Ford', 'Honda', 'Toyota', 'Lexus', 'KIA', 'SCION'); echo '<select name="car">'; echo '<option value="">Select...</option>'; for ($i = 0; $i < count($array); $i++) { echo '<option value="' . $i . '">' ; echo $array[$i] ; echo '</option>'; } echo '</select>'; ?>
Output
Example 2
main.html
<html> <head> <title>Dropdown</title> <script type="text/javascript" src="jquery.min.js"> </script> <script type="text/javascript"> $(document).ready(function() { $('div#car_list').load('car.php'); }); </script> </head> <body> <form> <table> <tr> <td>Name:</td> <td><input type="text" name="name"/></td> </tr> <tr> <td>Car:</td> <td><div id="car_list"></div></td> </tr> <tr> <td>Price:</td> <td><input type="text" name="price"/></td> </tr> <tr> <td></td> <td><input type="submit"/></td> </tr> </table> </form> </body> </html>
car.php
<?php $array = array('BMW', 'Ford', 'Honda', 'Toyota', 'Lexus', 'KIA', 'SCION'); echo '<select name="car">'; echo '<option value="">Select...</option>'; for ($i = 0; $i < count($array); $i++) { echo '<option value="' . $i . '">' ; echo $array[$i] ; echo '</option>'; } echo '</select>'; ?>
Output
Related Links
Dynamic HTML From Array
Dynamic HTML From Database
Dynamic HTML with Ajax
- Dynamic Drop Down List with Ajax
- Dynamic List with Ajax
- Dynamic Radio with Ajax
- Dynamic Checkbox with Ajax
- Dynamic Form with Ajax
Others Related