how to change dropdowns values based on a selection of another dropdown using jquery

前端 未结 3 546
傲寒
傲寒 2020-12-11 09:46

I have my first dropdown with 2 selections: Standard Glass and Tempered glass. I have another dropdown where the user can select the width of the glass.

My problem:

3条回答
  •  鱼传尺愫
    2020-12-11 09:58

    I would suggest having just two selects, then changing the 2nd select based on what is selected in the first.

    $('#typeOfGlass').on('change', function(){
        $('#glassWidth').html('');
        if($('#typeOfGlass').val()==15){
            $('#glassWidth').append('');
            $('#glassWidth').append('');
            $('#glassWidth').append('');
        }else{
            $('#glassWidth').append('');
            $('#glassWidth').append('');
            $('#glassWidth').append('');
            $('#glassWidth').append('');
        }
    });
    

    Here is a working example: https://jsfiddle.net/6hmpa1ax/

提交回复
热议问题