1

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.

4
  • 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? Commented Mar 30, 2017 at 14:48
  • Can you post the whole code of this HTA or its link if it is so big ! What is e(....) ??? Commented Mar 31, 2017 at 0:11
  • @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. Commented Mar 31, 2017 at 11:03
  • @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. Commented Mar 31, 2017 at 11:05

1 Answer 1

1

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()">
Sign up to request clarification or add additional context in comments.

Comments

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.