PHP HTML Dynamic Checkbox From with Ajax
From w3cyberlearnings
Contents |
PHP Dynamic Checkbox with Ajax
Generate HTML Checkbox with Ajax.
Example 1
<html> <head> <title>Checkbox</title> <script type="text/javascript" src="jquery.min.js"> </script> <script type="text/javascript"> $(document).ready(function() { $('div#car_list').load('cars.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></td> <td><input type="submit"/></td> </tr> </table> </form> </body> </html>
cars.php
Cars.php is the server side program and it calls by Ajax to fill in the content. You may be able to use this concept to query the database and generate dynamic checkbox.
<?php $array = array('BMW', 'Ford', 'Honda', 'Toyota', 'Lexus', 'KIA', 'SCION'); for ($i = 0; $i < count($array); $i++) { echo "<input type=\"checkbox\" name=\"car[]\" value=\"{$array[$i]}\" id=\"id{$array[$i]}\"/>"; echo "<label for=\"id{$array[$i]}\">$array[$i]</label><br/>"; } ?>
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