Once again I was bitten by the manner in which the difference browsers report the value of the disabled attribute. I decided to test the different ways of using the disabled attributes and record my results.
What I learned from all of my testing is:
- Use disabled (HTML 4.01 only) or disabled=”disabled” (HTML or XHTML) to set in markup.
- When setting via scripting use one of the following to disable and enable, respectively
- inputObj.disabled=true and inputObj.disabled=false via boolean values;
- inputObj.disabled=”disabled” and inputObject.disabled=”” via string values;
- inputObj.setAttribute(“disabled”, “disabled”) and inputObj.removeAttribute(“disabled”)
- When testing for the disabled attribute on an input element, use inputObject.disabled for consistent results between browers.
Full testing results are tablulated at Testing the Disabled Attribute.