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>
Adding dynamic content in an HTA
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.
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.
Adding dynamic content in an HTA
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.
<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.
- monicafanton
- Posts: 7
- Last visit: Thu Feb 01, 2024 5:46 am
Adding dynamic content in an HTA
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.