1

I have the following JavaScript to disable a dropdownlist in a ASP.NET page, which gets called when I click a button.

function disableDropDown(DropDownID)
{
  document.getElementById(DropDownID).disabled = true;
  return false; 
}

I wanted to use the same button to toggle between enable and disable for that dropdownlist. How do I do this?

2 Answers 2

3

You just have to invert the boolean disabled attribute:

function toggleDisableDropDown(dropDownID) {
  var element = document.getElementById(dropDownID); // get the DOM element

  if (element) { // element found
    element.disabled = !element.disabled; // invert the boolean attribute
  }

  return false; // prevent default action
}
Sign up to request clarification or add additional context in comments.

Comments

0
function toggleDisableDropDown(DropDownID)
{
  var sel = document.getElementById(DropDownID);
  sel.disabled = !sel.disabled;
  return false; 
}

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.