locked
Pass an html command from a variable in an hta RRS feed

  • Question

  • Hey guys, so I am writing an hta that will compare file versions and change the color of a text box on the hta form. I've managed to work out all of the bugs except the very last one. Here's what I need to pass:

    textfield(variable from onpage load script).style.background = "red"

    My variable is set by which text box I am addressing in the script. For instance, I want to change textfield3 red because Adobe Reader is out of date. I wrote the script in VBScript and echoed the color it was supposed to turn to my command window, but when I transferred the script to my hta, it doesn't turn because the variable "3" is not parsing to the area between the parenthesis above. Any idea how to use my variable with the above command?  

    Wednesday, December 2, 2015 5:22 PM

Answers

  • Nice, Bill, but it still needs .style., such as document.getElementById("textfield" & tbno).style.background = "white".
    Wednesday, December 2, 2015 8:00 PM
  • Thx for spotting that tommymaynard. Amended.

    -- Bill Stewart [Bill_Stewart]

    Wednesday, December 2, 2015 8:03 PM
  • I think I understand.

    Instead of this:


    textfield("tbno").style.background = "white"

    try this:


    document.getElementById("textfield" & tbno).style.background = "white"
    



    -- Bill Stewart [Bill_Stewart]



    Wednesday, December 2, 2015 7:49 PM

All replies

  • Please post a sample HTA that contains only the minimal amount of code needed to reproduce the problem.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, December 2, 2015 5:39 PM
  • <html>
    <head>
        <title>Software Inventory List</title>
    </head>
    
        <HTA:APPLICATION 
            SysMenu="no"
        >
    
    <script language = "VBScript">
    
    Sub Window_OnLoad
         strComputer = "."
           
    
         window.resizeTo 500,570
         On Error Resume Next
    
    'extracted file versions - simplified for space
    AdobFlash = 18
    AdobRead = 10
    IEVer = 10
    
    'Most Current Version - simplified for space
    AdobFlashCur = 19
    AdobReadCur = 11
    IEVerCur = 10
    
    
    'Populate Text Box
    textfield1.value = AdobFlash
    textfield2.value = AdobRead
    textfield3.value = IEVer
    
    'Set Arrays
    swarray = Array(AdobFlash,AdobRead,IEVer)
    arr1 = Array(AdobFlashCur,AdobReadCur,IeVerCur)
    
    
    'Compare Versions
    tbno = 0
    i = 0
    j = 0 
    Do until j=3
       tbno = tbno + 1 
              swver2 = swarray(i) 
              swver1 = Arr1(j) 
          
          If swver2 >= swver1 Then
            	textfield("tbno").style.background = "white"
          Else
    	        textfield("tbno").style.background = "red"
          End If
       i = i + 1
       j = j + 1
    
    loop
    
    End Sub
    
    </Script>
    
    <body bgcolor="Blue">
    <p><input type="button" value="X" onClick="self.close()" style="float: right;"></P>
    
    <p><font color="white"><b>Adobe Flash Version</b></font> &nbsp &nbsp &nbsp
    <input type="text" id="textfield1"></p>
    <p><font color="white"><b>Adobe Reader Version</b></font> &nbsp &nbsp &nbsp
    <input type="text" id="textfield2"></p>
    <p><font color="white"><b>Internet Explorer Version</b></font> &nbsp &nbsp &nbsp
    <input type="text" id="textfield3"></p>
    
    
    
        </body>
    </html>

    I need to have the first two change colors to red because their file version is out of date.


    Wednesday, December 2, 2015 6:16 PM
  • Step 1 is to remove "On Error Resume Next".

    Don't use that line of code unless you understand precisely what it does.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, December 2, 2015 6:18 PM
  • Yeah, I forgot to remove that from my sub. I removed it and now it gives me a type mismatch on textfield.
    Wednesday, December 2, 2015 6:43 PM
  • You don't have a document element named "textfield".


    -- Bill Stewart [Bill_Stewart]

    Wednesday, December 2, 2015 7:21 PM
  • I know. I am trying to use my variable "tbno" from the script part. It refers to the text box number. I want the first iteration through the do loop to be textfield1, the second textfield2, and the third textfield3.

    Wednesday, December 2, 2015 7:24 PM
  • I think I understand.

    Instead of this:


    textfield("tbno").style.background = "white"

    try this:


    document.getElementById("textfield" & tbno).style.background = "white"
    



    -- Bill Stewart [Bill_Stewart]



    Wednesday, December 2, 2015 7:49 PM
  • Nice, Bill, but it still needs .style., such as document.getElementById("textfield" & tbno).style.background = "white".
    Wednesday, December 2, 2015 8:00 PM
  • Thx for spotting that tommymaynard. Amended.

    -- Bill Stewart [Bill_Stewart]

    Wednesday, December 2, 2015 8:03 PM
  • Thanks Bill and Tommy. That worked like a charm!!
    Wednesday, December 2, 2015 8:13 PM
  • So the question is actually this:

    How do I refer to a document element by a variable name?

    The answer is to use the getElementById function of the document object.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, December 2, 2015 8:21 PM