3
Option Explicit 
Dim output, ProxyEnable, ProxyServer, wshShell, doc

Sub Window_onLoad
    loadProxySettings()
End Sub 

Set wshShell = CreateObject("WScript.Shell")
ProxyEnable = wshShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
ProxyServer = wshShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer")

Function loadProxySettings()
    If ProxyEnable = 1 Then
        proxyStatus.className = "enabled"
        proxyStatus.innerHTML = "Proxy aktiv"

        toggleProxyButton.value = "Proxy deaktivieren"

        proxyServer.value = ProxyServer
    Else
        proxyStatus.className = "disabled"
        proxyStatus.innerHTML = "Proxy deaktiviert"

        toggleProxyButton.value = "Proxy aktivieren"

        proxyServer.value = ProxyServer
    End If 
End Function

Just can't find the problem why this is giving me the error:

Object required "ProxyStatus"

(and yes I have a span element with the id of proxyStatus)

9
  • 1
    Set doc = document seems to be setting doc equal to something which is uninitialized. Commented Feb 25, 2016 at 22:21
  • hmm tried it too, but still the same.. thats why i am so irritated..hmm thanks tho Commented Feb 25, 2016 at 22:23
  • Edit your code to show what doc is being set equal to. Commented Feb 25, 2016 at 22:25
  • The variable document is still not initialized in your code. Where do you expect its content to come from? Is this perhaps used in an ASP or HTA? Commented Feb 25, 2016 at 22:29
  • 1
    yap.. its a hta.. it should be already declerated oa? Commented Feb 25, 2016 at 22:34

2 Answers 2

1

Go back to this code

Set ProxyStatus = document.getElementById("proxyStatus")
Set ToggleProxyButton = document.getElementById("toggleProxy")
Set ProxyServerInput = document.getElementById("proxyServer")

The only mistake here as long as the HTML is correctly formed is the use of Set when you are just referencing existing objects in the DOM. Try removing the Set from these lines like this;

ProxyStatus = document.getElementById("proxyStatus")
ToggleProxyButton = document.getElementById("toggleProxy")
ProxyServerInput = document.getElementById("proxyServer")
Sign up to request clarification or add additional context in comments.

Comments

0

In HTAs you can use the ID of ID'd elements like variables, i.e. if you have an element like this:

<p>foo <span id="proxyStatus">something</span> bar</p>

you should be able to use it in your code like this without having to do anything first:

MsgBox proxyStatus.innerText

3 Comments

thanks for that.. i know but it doesn't work either .. still the same, it seems that the getElementById doesn't find the element in the DOM..
@steve If it's not finding the DOM elements it may not see the HTML as a valid structure, try validating the HTML.
Did you remove the getElementById() statements, so they don't mess up existing variables? Does your HTML contain frames or iframes?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.