Sam H Sam H - 6 months ago 29
HTML Question

Object does not support this property or method - InnerHTML VBS HTA Issue

This has got to be an easy one, but I'm pulling my hair out.

I'm writing a new HTA, written several before now - but I can't get the InnerHTML property to work.

The error I recieve is on line 10. The error is:

Object doesn't support this property or method: 'text1.innerHTML'


I have compared my text1.innerHTML code areas to that in other HTA's that work fine and cannot see any difference. I've also checked the header / meta info and there's nothing different there.

Below are the snips of code:

<script language="VBScript">

Sub Window_OnLoad()

Self.resizeTo 800,670

Set objShell = CreateObject("WScript.Shell")
strShort = objShell.ExpandEnvironmentStrings("%USERDOMAIN%")
If strShort = "DOMAINA" Then text1.innerHTML="VPN Type 1"
If strShort = "DomainB" Then text1.innerHTML="VPN Type 2"
'This method will be called when the application loads
'Add your code here
End Sub

Sub EnableUpgrade()
If UACheckbox.Checked = True Then
UpgradeButton.Disabled = False
Else
UpgradeButton.Disabled = True
End If
End Sub

Sub OnClickButtonUpgradeButton()
'This method will be called when button "UpgradeButton" is clicked
'Add your code here
End Sub
</script>


<html>
<head>
<title>Test HTA</title></title>
<link href="Main.css" rel="stylesheet" type="text/css" />
<HTA:APPLICATION
APPLICATIONNAME="Babcock GlobalProtect Deployment"
ID="GlobalProtectDeployment"
VERSION="1.0"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
SCROLL="auto"/>
</head>


<body bgcolor="white">
<div class="wrappr">
<table class="top">
<tr class="top">
<td colspan="2">
<div class="wrapper">
<div class="topone" align=left><img style="width:125px;border:0;" vertical-align"center" src="WebVersion.png"></div>&nbsp;&nbsp&nbsp;&nbsp
<div class="topthree"><h1>Test HTA</h1>
</td>
</tr>
</table>
<table>
<tr><td>
<br>This upgrade will replace the <span ID = "Text1"> VPN software on this computer. This is mandatory, as <span ID = "text1"> will soon be decomissioned. The new VPN software that will be installed is VPNC.
</td></tr>
<br>
<input onclick="EnableUpgrade "type="checkbox" name="UACheckbox" id="UACheckbox">&nbspI confirm I have completed the above requirements
<br>
<input type="button" name="UpgradeButton" id="UpgradeButton" value="Upgrade" onclick="OnClickButtonUpgradeButton" disabled>
</table>
</div>
<!--Add your controls here-->


<!--{{InsertControlsHere}}-Do not remove this line-->
</body>
</html>

Answer

You are not closing the span tag in:

<br>This upgrade will replace the <span ID = "Text1"> VPN software on this computer. This is mandatory, as <span ID = "text1"> will soon be decomissioned. The new VPN software that will be installed is VPNC.

And id of elements should be unique in the page.

I think what you need is:

<br>This upgrade will replace the <span ID = "Text1"></span> VPN software on this computer. This is mandatory, as <span ID = "Text2"></span> will soon be decommissioned. The new VPN software that will be installed is VPNC.

And in the onLoad function,

If strShort = "DOMAINA" Then 
    Text1.innerHTML="VPN Type 1"
    Text2.innerHTML="VPN Type 1"
End if