Skip to main content
Topic: Disable dropdown item based on selection done on other dropdown box (Read 1523 times) previous topic - next topic

Disable dropdown item based on selection done on other dropdown box

I am working with two dropdown selects with same options. I want to disable an item if that item is selected in other dropdown. i.e. if I am selecting one item its disabled in other dropdown. But I am having trouble doing it. when I am new to PHPrad, jquery and AJAX. PLease guide me. Appreciate your help.

Re: Disable dropdown item based on selection done on other dropdown box

Reply #1
This is the code that worked for @Abou‍ 
Code: [Select]
$('#ctrl-f_warehouse_id').on('change', function(){ 
    $('#ctrl-l_warehouse_id')
        .find('option')
        .remove()
        .end();
    $('#ctrl-l_warehouse_id').attr("placeholder", "Sélectionnez une valeur");
    $("#ctrl-f_warehouse_id > option").each(function() {
        if($(this).val() != $('#ctrl-f_warehouse_id').val()){
            $('#ctrl-l_warehouse_id').append(new Option(this.text, this.value));
        }
    });
});

Re: Disable dropdown item based on selection done on other dropdown box

Reply #2
This is the code that worked for @Abou
Code: [Select]
$('#ctrl-f_warehouse_id').on('change', function(){ 
    $('#ctrl-l_warehouse_id')
        .find('option')
        .remove()
        .end();
    $('#ctrl-l_warehouse_id').attr("placeholder", "Sélectionnez une valeur");
    $("#ctrl-f_warehouse_id > option").each(function() {
        if($(this).val() != $('#ctrl-f_warehouse_id').val()){
            $('#ctrl-l_warehouse_id').append(new Option(this.text, this.value));
        }
    });
});


Hi wilvin, where to put that code ?