Hi,
I tried to create four dropdown lists as main category and sub categories which depends on the above list
I tried to run it on my local host and it works fine but when i want to insert the value of the second list in my database it doesn't work
I did my coding based on the link below.
Click Here
This is my main code that im working on:
That part has to take the value from the database for each changement by calling loadsubcat.php
$(document).ready(function() {
$("#parent_cat").change(function() {
$(this).after('<div id="loader"><img src="img/loading.gif" alt="loading subcategory" /></div>');
$.get('loadsubcat.php?parent_cat=' + $(this).val(), function(data) {
$("#sub_cat").html(data);
$('#loader').slideUp(200, function() {
$(this).remove();
});
});
});
});
</script>
Here is the loadsubcat.php
<?php
include('config.php');
//require 'database.php';
$parent_cat = $_GET['parent_cat'];
//$pdo = Database::connect();
//$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = mysql_query("SELECT * FROM scorejour WHERE id_joursemaine = {$parent_cat}");
while($row = mysql_fetch_array($query)) {
echo "<option value='$row[id_score]'>$row[score]</option>";
}
?>
Here is the get method that i use:
<?php
include('config.php');
require 'database.php';
mysql_query("set NAMES utf8");
$query_parent = mysql_query("SELECT * FROM joursemaine") or die("Query failed: ".mysql_error());?> <form style="margin-left:400px;" class="form-horizontal" action="updateChauf2.php?id=<?php echo $id?>" method="post"> <div class="control-group"> <label style="color:white;" for="category">parent_cat:</label> <select name="parent_cat" id="parent_cat" onchange="myFunction()"> <?php while($row = mysql_fetch_array($query_parent)): ?> <option value="<?php echo $row['id_joursemaine']; ?>"><?php echo $row['joursemaine']; ?></option> <?php endwhile; ?> </select> <br/><br/> </div> <div class="control-group"> <label style="color:white;" for="sub_cat">الرصيد المضاف</label> <select id="sub_cat" onchange="changeTest()" name="sub_cat"></select> </div> </form>
can you help me please to solve my problem