0

I am new to JQuery. I have searched for a solution but couldn't find any solution. I have 3 select box and the option selected in the first select box needs to removed from the next two select box. I have the code which actually hides the selected option in FF and chrome. But in IE it is not getting hidden. Also i need to bring back the selected option, if the user changes his mind and re-select the option he has already selected in first select box. Can someone help me out. Any help is much appreciated.

var array= [];
$(document).ready(function(){
    $('select').on('change', function(event ) {
        $('select').not(this).find('option').show();
        var value = $(this).val();
        //alert(value);
        array.push(value);
        for (var i = 0; i < array.length; i++) {
            // Here i am disabling the option as well as hiding. Because in IE hide does not work.
            $('select').not(this).find('option[value="'+array[i]+'"]').attr('disabled','disabled').hide();
        }
    });
});
1

1 Answer 1

2

Try this,

$("#first_select").change(function(){
    $("#second_select option,#third_select option").removeAttr("disabled");
    $.each($("#first_select").val(), function( index, value ) {
       $("#second_select option[value="+value+"]").attr("disabled","disabled");
       $("#third_select option[value="+value+"]").attr("disabled","disabled");
    });      
});

http://jsfiddle.net/anunaydahal/h8n1agdp/11/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.