Creating a Dependent Dropdown List with PHP, jQuery and Ajax
A sample application to show how dependable dropdown list can be implemented
CREATE TABLE IF NOT EXISTS `categories` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `category_name` VARCHAR(100) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS `subcategories` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `categoryID` INT(11) NOT NULL, `subcategory_name` VARCHAR(100) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB;
<?php ?>
<?php include('config.php'); ?>
<!doctype html> <html> <head> <meta charset="utf-8"> <script type="text/javascript"> $(document).ready(function() { $("#parent_cat").change(function() { $.get('loadsubcat.php?parent_cat=' + $(this).val(), function(data) { $("#sub_cat").html(data); $('#loader').slideUp(200, function() { $(this).remove(); }); }); }); }); </script> </head> <body> <form method="get"> <select name="parent_cat" id="parent_cat"> <?php while($row = mysql_fetch_array($query_parent)): ?> <?php endwhile; ?> </select> </form> </body> </html>
<?php include('config.php'); $parent_cat = $_GET['parent_cat']; echo "<option value='$row[id]'>$row[subcategory_name]</option>"; } ?>
I am able to retrieve the data,it works well..but how am I suppose to do if I want to insert both of the selected data to the database because the form use GET method, as we know that we must use POST as the form method to insert the data to the database..??anyone please help me... !!
"dependent dropdown listand insert to another table. How to to execute it?? Thank for this helpfull tutorial.