I have some code on a classic ASP page that is attempting to get the innerHTML
of a <div>
element.
Dim oElm
Set oElm = document.getElementById("screenDiv")
if oElm Is Nothing then
'''
else
document.getElementById("screenDiv").innerHTML = ""
end if
I've tried the above but I'm getting the Object Required error.
What do I need to do to get around this error?
NOTE: client side VBScript is outdated, deprecated, and doesn't work in any modern browser including newer versions of IE.
This means the code is located before the element, so when it executes, such element does not exist.
To solve this, have the code execute in the onload
event:
<script type="text/vbscript">
Set window.onload = GetRef("WindowLoad")
Function WindowLoad
Dim oElm
Set oElm = document.getElementById("screenDiv")
if oElm Is Nothing then
MsgBox("element does not exist")
else
oElm.innerHTML = ""
end if
End Function
</script>
Credit for the correct way goes to Korikulum, and the official documentation can be found here.
Live test case. (IE only)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With