Jump to: navigation, search

PHP HTML Dynamic Radio From with Ajax

From w3cyberlearnings

Contents

PHP Dynamic Radio Button Uses Ajax

Use Ajax to generate a dynamic Radio button.

Example 1

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('cars.php');
});
</script>
</head>
<body>
<form>
<table>
	<tr>
		<td>Email:</td>
		<td><input type="text" name="email"/></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

<?php
$array = array('BMW', 'Ford', 'Honda', 'Toyota', 'Lexus', 'KIA', 'SCION');


for ($i = 0; $i < count($array); $i++) {
	echo "<input type=\"radio\" name=\"car\" value=\"{$array[$i]}\" id=\"id{$array[$i]}\"/>";
	echo "<label for=\"id{$array[$i]}\">$array[$i]</label><br/>";
}

?>

Output

Php html dynamic radio ajax 1.png

Related Links


Dynamic HTML From Array
  1. Dynamic Drop Down List with Array
  2. Dynamic List with Array
  3. Dynamic Radio with Array
  4. Dynamic Checkbox with Array
Dynamic HTML From Database
  1. Dynamic Drop Down List with Database
  2. Dynamic List from Database
  3. Dynamic Radio from Database
  4. Dynamic Checkbox from database
Dynamic HTML with Ajax
  1. Dynamic Drop Down List with Ajax
  2. Dynamic List with Ajax
  3. Dynamic Radio with Ajax
  4. Dynamic Checkbox with Ajax
  5. Dynamic Form with Ajax
Others Related
  1. Dynamic Drop down with default option
  2. How to retrieve Form Data
Navigation
Web
SQL
MISC
References