I have a problem determining status of an input field. I want JS to determine whether it is disabled or enabled but my code below always return ‘false’. What am I doing wrong? Thanks
<input name="ctl00$ctl00$ctl00$ctl00$ContentPlaceHolderDefault$RobinBodyPlaceHolder $LoggedInBodyPlaceHolder$AddEditUser1$EmailTextBox" type="text" value="email@mail.com" id="ContentPlaceHolderDefault_RobinBodyPlaceHolder_LoggedInBodyPlaceHolder_AddEditUser1_EmailTextBox" class="EmailTextBox" disabled="disabled"/>
function ConfirmEmailChange() {
alert($('.EmailTextBox').disabled==true);
}
You’re trying to access the
disabledproperty of a jQuery object (I’m assuming it’s jQuery, but it could be some other JS library using the$character), but jQuery objects don’t have adisabledproperty.If it is jQuery, you can access the actual DOM node contained within the jQuery object using array notation:
Alternatively, you can use the
getmethod:Or, as others have shown, you can use the jQuery
propmethod. Notice that I’ve removed the== truepart, asdisabledis a boolean property and will returntrueorfalseanyway.