Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Disable option in dropdown

Guys i have used the following code to disable an option using jQuery (jquery-1.4.2.min).The disable happens in Firefox , but not in IE.

<SELECT NAME="SCOPE" id="SCOPE">  
 <OPTION VALUE="G"> Global
 <OPTION VALUE="D"> Dynamic  
</SELECT>


 $("#SCOPE option[value='G']").attr("disabled","disabled");
 $("#SCOPE option[value='D']").attr("selected", "selected");
like image 662
Dead Programmer Avatar asked Feb 09 '11 11:02

Dead Programmer


1 Answers

I think i might be wrong but it could be because the select rather than option can be disabled. Since firefox is great and IE sucks, well you can guess why :) you having that problem. Use css to grey out the text of that option.

then on jquery do something like this.

$('#SCOPE').change(function(){
  if($('#SCOPE option[value="'+$(this).val()+'"]').attr('disabled') == 'disabled'){
    alert('Its disabled you cannot select this option');
  }
});

BTW. double check the code as I have not tested this :)

like image 101
Val Avatar answered Sep 18 '22 09:09

Val