$(document).ready(function() {
$('#<%=ddlContinents.ClientID %>').change(function() {
var element = $(this);
var totalLength = element.children().length;
if ($(this).disabled == false) { $(this).disabled = true; }
});
});
What I am trying to do is fire off the change event of the dropdownlist
and on change making this dropdownlist
disabled. The code is firing and everything, but it does not disable the dropdownlist
.
This portion of the code is not working:
if ($(this).disabled == false) { $(this).disabled = true; } });
You should use .prop()
for jQuery 1.6+ or .attr()
for earlier versions of jQuery:
> jQuery 1.6:
$(document).ready(function() {
$('#<%=ddlContinents.ClientID %>').change(function() {
var element = $(this);
var totalLength = element.children().length;
if (!$(this).prop("disabled")) {
$(this).prop("disabled", true);
}
});
});
< jQuery 1.6:
$(document).ready(function() {
$('#<%=ddlContinents.ClientID %>').change(function() {
var element = $(this);
var totalLength = element.children().length;
if (!$(this).attr("disabled")) {
$(this).attr("disabled", "disabled");
}
});
});
if (!$(this).attr("disabled")) { $(this).attr("disabled","disabled"); }
If you want to enable it later on, you gotta do:
$(this).removeAttr("disabled");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With