0

How do i disable selected options in many drop-down list boxes but leave one of them enabled? The box that i need to have the options enabled has the following html code and has and id of (x_captain). Other options in the boxes are disabled dynamically. List box whose all options must be re-enabled for selection.

HTML:

<select class="x_captain" id="x_captain" name="x_captain">
<option value="1" disabled="disabled">W.SZCZESNY, GK</option>
<option value="13" disabled="disabled">E.VIVIANO, GK</option>
</select>

i have the following Code that disables all the duplicates in all select boxes.

jQuery:

<script>
$('select').click(function() {
  var selections = [];
  $('select option:selected').each(function(){
    if($(this).val())
        selections.push($(this).val());
  })
  $('select option').each(function() {
     $(this).attr('disabled', $.inArray($(this).val(),selections)>-1 && !$(this).is(":selected"));
  });
});
</script>

Thank you

3
  • Please provide a better explanation. Do you have multiple select elements with the same options and want to disable the selected option of one of them in all other select elements? Commented Mar 9, 2014 at 18:33
  • need more info on this Commented Mar 9, 2014 at 18:33
  • The code above is working fine to disable selected options in other select boxes but there is one select box that gets has all the selected options so duplicates are allowed in that select box. I want to be able to select elements that box,(i.e, all of them enabled) i have not been successful at all. Commented Mar 9, 2014 at 18:39

2 Answers 2

0
$('select:not(#x_captain) option').each(function() {
 $(this).attr('disabled', $.inArray($(this).val(),selections)>-1 && !$(this).is(":selected"));
  });
0
0
<script>
$('#x_captain').click(function() {
    $('#x_captain option').each(function(){
     if($(this).attr('selected') == selected)
{
  $(this).attr("disabled",false);
}
else
{
$(this).attr("disabled",true);
}
});

});
</script>
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.