views:

9616

answers:

2
$(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; } });
+10  A: 

Try this:

$(document).ready(function() {
  $('#<%=ddlContinents.ClientID %>').change(function() { 
   var element = $(this);
   var totalLength = element.children().length;
   if ($(this).attr("disabled") == false) { $(this).attr("disabled","disabled"); } 
  });
});
baens
Thank you though, but did not work.
Shiva
oops, try $(this).attr("disabled") == false
baens
Thank you , that is way.
Shiva
+4  A: 
if (!$(this).attr("disabled")) { $(this).attr("disabled","disabled"); }

If you want to enable it later on, you gotta do:

$(this).removeAttr("disabled");
Paolo Bergantino