Ajax Tutorial: Dynamic Loading of ComboBox using jQuery and Ajax in PHP
Here is a script for beginners to create a dynamic loading of dropdown. Simple solution which is created by jQuery.
[ad#ad-3]
1
2
3
4
5
6
|
CREATE TABLE IF NOT EXISTS `ajax_categories` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category` varchar(50) NOT NULL,
`pid` int(11) NOT NULL,
PRIMARY KEY (`id`)
)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<?php
if($_REQUEST)
{
$id = $_REQUEST['parent_id'];
$query = "select * from ajax_categories where pid = ".$id;
$results = mysql_query( $query);?>
<select name="sub_category" id="sub_category_id">
<option value="" selected="selected"></option>
<?php
while ($rows = mysql_fetch_assoc(@$results))
{?>
<option value="<?php echo $rows['category'];?> ID=<?php echo $rows['id'];?>"><?php echo $rows['category'];?></option>
<?php
}?>
</select>
<?php
}?>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<div class="both">
<h4>Select Category</h4>
<select name="search_category" id="search_category_id">
<option value="" selected="selected"></option>
<?php
$query = "select * from ajax_categories where pid = 0";
$results = mysql_query($query);
while ($rows = mysql_fetch_assoc(@$results))
{?>
<option value="<?php echo $rows['id'];?>"><?php echo $rows['category'];?></option>
<?php
}?>
</select>
</div>
<div class="both">
<h4 id="show_heading">Select Sub Category</h4>
<div id="show_sub_categories" align="center">
<img src="loader.gif" style="margin-top:8px; float:left" id="loader" alt="" />
</div>
</div>
|
Comments
Post a Comment