Hello.

There are 4 selects (with ID #model, #color, #size, #amortizator), the last 3 depend on the value of 1 select. Having chosen the value in the upper select, the available values ​​in the lower 3 should load.

This is done by me:

$(document).ready(function(){ $("#model").change(function(){ var ramavalue = $("#model option:selected").val(); //alert(ramavalue); $("#color").load('/const/api.php?ramaid='+ ramavalue +'&color=y'); $("#size").load('/const/api.php?ramaid='+ ramavalue +'&size=y'); $("#amortizator").load('/const/api.php?ramaid='+ ramavalue +'&amortizator=y'); var amzid = $("#amortizator option:selected").val(); $(".amortizatordesc").load('/const/api.php?amzid='+ amzid +'&amortizatordesc=y'); }); $("#amortizator").change(function(){ var amzid = $("#amortizator option:selected").val(); $(".amortizatordesc").load('/const/api.php?amzid='+ amzid +'&amortizatordesc=y'); }); }); 

the top selector has #model, the values ​​of the remaining 3 are normally loaded when selecting / changing the option at the top.

The problem is in the extra field. The <p></p> with the .amortizatordesc class should load a description of the value from 4 selects with the #amortizator id. But when you open the page initially in the tag is empty. When changing the same value in 1 selector, the description of the past select is loaded into the tag. That is, there is a lag.

When changing the value manually in 4 #amortizator selects, everything is fine. And when changing the upper value of the #model select shows the description of the previously selected select.

Not quite clearly written, but I hope someone will understand what my problem is.

    1 answer 1

    Just call the $ ('# model'). At the end of the function. Change the change event for the last select:

     $("#model").change(function(){ // ... Ваш предыдущий код $("#amortizator").trigger('change'); }); 

    An example .

    • something doesn't work out for me, without changes - Saturn
    • I hurried, did not take into account that you are loading from the server. You need to add a trigger ('change') to the callback of the last .load () that changes the desired select: in other words, you should trigger just ONLY after receiving the data from the server and inserting it into this select. - Zhukov Roman
    • $ (". amortizatordesc"). load ('/ const / api.php? amzid =' + amzid + $ ('# amortizator'). trigger ('change') + '& amortizatordesc = y'); - Saturn
    • Something like that? It still does not come out yet. - Saturn
    • No, read the load documentation. $ (". amortizatordesc"). load ('/ const / api.php? amzid =' + amzid + '& amortizatordesc = y', function () {$ ('# amortizator'). trigger ('change')}) ; - Zhukov Roman