You are viewing limited content. For full access, please sign in.

Question

Question

How to change dropdown Menu with javascript?

asked on May 31, 2018

Hi everybody,

 

 

In my form, I have two drop-down menus (Products and Format).

For the moment, the second (Format) has only 2 values

Depending on the value of the first drop-down menu, I want to change those of the second one.

For example, if the first is "CV", then the second one will have 90x55 and 90x50 but if the first one is "Flyer", then the second will be 210x100 and 297x210.

 

In my mind, I need to use javascript but I need help.

 

I do not want to use the database for that.

 

Any ideas?

Thank you very much.

 

Regards

 

1 0

Answer

SELECTED ANSWER
replied on May 31, 2018
$(document).ready(function(){
    $('#FirstDropDown).on('change',function(){
        if($('#FirstDropDown option:selected').val()=="CV"){
            $('#SecondDropDown option').remove();
            $('#SecondDropDown select')
            .append($('<option value="90x55">90x55</option>)'))
            .append($('<option value="90x50">90x50</option>)'))
        }
        if($('#FirstDropDown option:selected').val()=="Flyer"){
            $('#SecondDropDown option').remove();
            $('#SecondDropDown select')
            .append($('<option value="210x100">210x100</option>)'))
            .append($('<option value="297x210">297x210</option>)'))
        }
    })
})

Please double-check for syntax errors but something like above should work. Of course, you will have to change the id/selector for your two drop-downs accordingly.

Best,

Ken

4 0

Replies

replied on June 1, 2018

Thanks a lot! It's working ^^

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.