简体   繁体   中英

Javascript runtime error using IE11 on Win7: Unable to set property 'disabled' of undefined or null reference

I am currently working on some IE11 compatibility issues. The code is fully functional in compatibility mode as it was previously optimize last for IE5.

The affected code is as follows:

/*
 * This function sets the specified button state in the repair processing form
 */
function setOperationButton(buttonId, disabledState, sourceImage, styleCursor)
{
    var buttonElement = document.frmRepairProcessing.elements[buttonId];
    var sourceRoot = '<%=helper.getApplicationURL()%>' + '/zimages/' + '<%=localeString%>' + '/';
    buttonElement.disabled = disabledState;
    buttonElement.src = sourceRoot + sourceImage;
    buttonElement.style.cursor = styleCursor;   
}

So I am thinking the code simply needs to be updated to use getElementById, but I am not quite sure how to implement the specific form.

Please note: I have also tried document.forms().elements() and using .value as well.

I believe it will be acceptable to use below code to obtain buttonElement:

function setOperationButton(buttonId, disabledState, sourceImage, styleCursor)
{
    var buttonElement = document.getElementById(buttonId);
    var sourceRoot = '<%=helper.getApplicationURL()%>' + '/zimages/' + '<%=localeString%>' + '/';
    buttonElement.disabled = disabledState;
    buttonElement.src = sourceRoot + sourceImage;
    buttonElement.style.cursor = styleCursor;   
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM