I recently found out (unfortunately) that disabling an option with the disabled attribute does not work in IE 7. Odd. Here is my workaround using JQuery, it will gray out and disallow selection of all options with a disabled attribute.
$(document).ready(function() {
$('option[disabled]').css({'color': '#cccccc'});
$('select').change(function() {
if(this.options[this.selectedIndex].disabled) {
if(this.options.length == 0) {
this.selectedIndex = -1;
} else {
this.selectedIndex--;
}
$(this).trigger('change');
}
});
$('select').each(function(it) {
if(this.options[this.selectedIndex].disabled)
this.onchange();
});
});
s


#1 by tony c at October 10th, 2009
| Quote
awesome! exactly what i was looking for thank you!
#2 by borland at August 20th, 2010
| Quote
thanks, it works in IE6 and 7
JS code example:
$(“#selectID option[value='2']“).attr(“disabled”,”disabled”);
it’ll disable option value=”2″
#3 by Gator at August 11th, 2011
| Quote
Very nice! I’ve wrapped it in an if msie block so it only applies to internet explorer:
if ($.browser.msie && parseFloat($.browser.version) < 8){
//your code here
}
#4 by Jason at September 5th, 2011
| Quote
Thanks, this is exactly what I want