Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, all i have a problem with my code i build 3 dynamic drop downs in which values comes from database.when someone select a value from first drop down 2nd shows related values in it and when someone select value from 2nd drop down third shows related values.
in my case i have three categories in 2 categories all these 3 drop downs are used and in thired category only 2 are used. in edit page where all values shows from database i tried to get values in drop down 2 drop down that are used in all 3 categories work well but when i tried to get the value of thired drop down it affects third category and hides all drop down values.
Here is my code for first two categories using ajax jquery with php

What I have tried:

JavaScript
    var cid = <?php echo $cid = intval($_GET['cid']) ?>;

if(cid == 1 || cid == 2)
{
    //now back to dynamic drop down list work
    var brand_id = <?php echo $db_brand ?>;
    if(brand_id == <?php echo $db_brand ?>)
    {
        $.post("getbrandlist.php",{category:cid,brandid:brand_id}, function(brandlist){
            $("#brand").html(brandlist);

            //plateform id get from db and get it in drop down
            var plateform_id = <?php echo $db_plateform ?>;
            var model = <?php echo $db_model ?>;
            if(plateform_id == <?php echo $db_plateform ?> || model == <?php echo $db_model ?>)
            {
                $.post("getplateformlist.php",{brandid: brand_id,plateform: plateform_id},function(plateformlist){
                    $("#plateform").html(plateformlist);

                    //model id get from db and get it in drop down



                });

                $("#brand").change(function(){
                    var brand = $(this).val();
                    if(brand)
                    {
                        $.post("getplateformlist.php",{brandid: brand},function(plist){
                            $("#plateform").html(plist);

                            $("#plateform").change(function(){
                                var plateformid = $(this).val();
                                if(plateformid)
                                {
                                    $.post("getmodellist.php",{plateform: plateformid},function(mlist){
                                        $("#modellist").html(mlist);
                                    });
                                }
                            });
                        });
                    }
                });

            }
        });
    }
}

and for third category where unknown problem occurs code here

JavaScript
var brand_id = <?php echo $db_brand ?>;
    if(brand_id == <?php echo $db_brand ?>)
    {
        $.post("getbrandlist.php",{category:cid,brandid:brand_id}, function(brandlist){
            $("#brand").html(brandlist);

            //plateform id get from db and get it in drop down
            var plateform_id = <?php echo $db_plateform ?>;
            if(plateform_id == <?php echo $db_plateform ?>)
            {
                $.post("getplateformlist.php",{brandid: brand_id,plateform: plateform_id},function(plateformlist){
                    $("#plateform").html(plateformlist);
                });

                $("#brand").change(function(){
                    var brand = $(this).val();
                    if(brand)
                    {
                        $.post("getplateformlist.php",{brandid: brand},function(plist){
                            $("#plateform").html(plist);
                        });
                    }
                });

            }
        });
    }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900