Search code examples
domvbscriptinnerhtml

VBScript InnerHtml - Firing too early


So when running some code, along the lines of:

document.getElementById("getForge").style.display = "inline" ' this is hidden by default, show it.
DoStuffHere()
document.getElementById("getForge").style.display = "none" ' hide it again after DoStuffHere().

So I can show a popup and then hide it again when the function is done, the code seems to be actionned in the DOM before the function has completed its work (a download).

I was under the belief that VBScript would be carried out line by line until it reached that last style change, this has proven not to be the case, is there any way around this?

All I am trying to do is get a div to show until the process is complete and then hide it again.


Solution

  • The below code is MC ND's solution to the issue, I have simply changed around some of the variables and names involved.

    The setTimeout function did have a parenthesis issue however that is corrected in the below code.

    Function DoAlert
        Dim alert
        Set alert = document.getElementById("divForge")
    
        If alert.style.display = "inline" Then 
            Call GetForge()
            alert.style.display = "none"
        Else
            alert.style.display = "inline"
            setTimeout GetRef("DoAlert"), 50
        End If 
    
    End Function    
    

    Thank you very much for your help MC ND, very informative.