1
votes

I've got some code that is meant to hide a div in HTML if a variable is empty.

Sub checkBattery    
    If IsEmpty(e("batremaining")) Then
        batteryShow.style.visibility = "hidden"
    Else
        batteryShow.style.visibility = "visible"
    End If
End Sub

checkBattery

This is extremely frustrating me, because I have no idea why it is not working.

Here is my <div>:

<div id="batteryShow" class="panel panel-warning batteryShow">
    <div class="panel-heading">
        <h3 class="panel-title">Battery Percentage</h3>
    </div>
    <div class="panel-body">
        <center><div style="font-size:16px;font-weight:bold;">Battery Level: 100%</div></center>
    </div>
</div>

I am probably missing something extremely simple and easy to fix, but I cannot for the life of me figure out what.

1
Are you sure that testing for 'is not initialzed' (IsEmpty - msdn.microsoft.com/en-us/library/5cs4befa(v=vs.84).aspx) is correct? Do you want to check for an empty (i.e. zero length) string? What is e()? Exact line of error? - Ekkehard.Horner
Can you post the whole code of this HTA or its link if it is so big ! What is e(....) ??? - Hackoo
@Ekkehard.Horner No, it is the correct, the problem was I was calling the functions before the page was ready, so the fix was to use the onLoad function in the body to call the function. - GrumpyCrouton
@Hackoo I'm not really sure how that is relevant, I'm not asking about the if statement, I was asking about hiding a div, the function was calling everything correctly, it just wasn't working. I fixed it by running my checkBattery function when the page was ready instead of right when it gets to that code sequentially. - GrumpyCrouton

1 Answers

1
votes

So my problem was I was running the code too early.

What I did to fix it was I made a new function called handler, which I put calls to do things that I needed to do on page load.

Function handler()
    checkBattery
    ... ETC ...
End Function

And in the body of my script I used

<body onLoad="VBScript:handler()">