Adding dynamic content in an HTA

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 16 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
monicafanton
Posts: 7
Last visit: Thu Feb 01, 2024 5:46 am

Adding dynamic content in an HTA

Post by monicafanton »

I am trying to add dynamic content to an HTA, but I'm stuck on how to select a checkbox (dynamically added), click a button, and then perform an action based on whether the checkbox is checked.

The relevant portion of the script is here:

Sub Window_OnLoad
'Prompt the user for the search string strQuery = InputBox("What is the search string?")
' Get the domain name Set objRoot = GetObject("LDAP://rootDSE") strDomain = "LDAP://" & objRoot.Get("defaultNamingContext") ' Create recordset for computer names Set objList = CreateObject("ADOR.RecordSet") Set objList = CreateObject("ADOR.Recordset") objList.Fields.Append "ServerName", adVarChar, MaxCharacters objList.Open ' Create the connection Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" ' Query the directory Set objCommand.ActiveConnection = objConnection objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=computer)" & _ "(Name=*" & strQuery & "*));Name;subtree" ' Set up command properties objCommand.Properties("Page Size") = 1000 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.Properties("Cache Results") = False ' Put computer names into the list Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst 'Create the list While Not objRecordSet.EOF objList.AddNew objList("ServerName") = objRecordset.Fields("Name") objRecordSet.MoveNext Wend 'Alphabetize the list objList.Sort = "ServerName" 'Start at the beginning of the list objList.MoveFirst 'Go through the list and display each server name with a checkbox Do Until objList.EOF strComputer = objList.Fields.Item("ServerName") strHTML = ServerList.InnerHTML strHTML = strHTML & "<table><tr><td> </td><td>" & _ "<input type=""checkbox"" name=" & _ strComputer & ">" & strComputer & "</td></tr>" objList.MoveNext ServerList.InnerHTML = strHTML Loop End Sub

Sub RunScript If strComputer.Checked Then MsgBox ("The checkbox has been checked.") Else MsgBox("The checkbox has not been checked.") End IfEnd Sub

<body>
<BR><table width="100%"><tr><td><b>Server List:</b><td><input id=runbutton class="button" type="button" value="Run Script" name="run_button" onClick="RunScript"></td><td><input id=runbutton class="button" type="button" value="Cancel" name="run_button" onClick="Quit"></td></tr><tr><td>To remove servers from the list, select the checkbox next to the server name.<br></td></tr><td>
</td></td></tr></table> <span id="ServerList"></span>
</body>
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Adding dynamic content in an HTA

Post by jvierra »

If you need direct access to the properties of any object give teh eelement and id.

<input id="myinput" type="checkbox"...

if myinput.checked Then

...
Jose's method is excellent for grouped controls. Single items are easier with IDs. Don't use a name when you use an ID. In fact the newest HTML spec deprecates name. The latest schema disallows "name" as an attribute. DOn't mix "name" up with Jose's "TagName" TagName it INPUT, DIV, BODY..etc.

User avatar
monicafanton
Posts: 7
Last visit: Thu Feb 01, 2024 5:46 am

Adding dynamic content in an HTA

Post by monicafanton »

Yes, these methods work, but not really in my scenario. This is an HTA, and I'm trying to use a variable (strComputer). The problem is that the strComputer is not passed to Sub RunScript, so I get an error message when the button is clicked rather than being able to perform the operations within the sub.
This topic is 16 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked