Jquery dependent drop down boxes populate- how

后端 未结 3 472
滥情空心
滥情空心 2020-11-29 12:55

I\'ve got dependent drop down boxes as shown on scenario below. Could anyone please suggest how to achieve the result using JQuery/Javascript?

Scenario:



        
3条回答
  •  执笔经年
    2020-11-29 13:21

    var drop2 = $("select[name=drop2] option"); // the collection of initial options
    $("select[name=drop1]").change(function(){
        var drop1selected = parseInt(this.value); //get drop1 's selected value
        $("select[name=drop2]")
                         .html(drop2) //reset dropdown list
                         .find('option').filter(function(){
                            return parseInt(this.value) < drop1selected; //get all option with value < drop1's selected value
                          }).remove();  // remove
    });
    

    http://jsfiddle.net/HTEkw/

提交回复
热议问题