View Single Post
Old 06-12-2009   #2 (permalink)
T Lavedas


 
 

Re: InnerHTML not working

On Jun 12, 4:26*pm, MattW <winber...@xxxxxx> wrote:
Quote:

> Hi all. *I've got my array working, and pulling data, but my sGroup
> variable isn't populating my innerHTML.
>
> <HTML>
> * * * * <HEAD>
> * * * * * * * * <TITLE>Users Group Migration HTA</TITLE>
> * * * * * * * * <HTA:APPLICATION
> * * * * * * * * * * * * ID="MyApp"
> * * * * * * * * * * * * APPLICATIONNAME="Template"
> * * * * * * * * * * * * BORDER="thick"
> * * * * * * * * * * * * BORDERSTYLE="complex"
> * * * * * * * * * * * * CAPTION="yes"
> * * * * * * * * * * * * CONTEXTMENU="no"
> * * * * * * * * * * * * ICON="http://YourURL/your icon.ico"
> * * * * * * * * * * * * INNERBORDER="yes"
> * * * * * * * * * * * * MAXIMIZEBUTTON="yes"
> * * * * * * * * * * * * MINIMIZEBUTTON="yes"
> * * * * * * * * * * * * NAVIGABLE="no"
> * * * * * * * * * * * * SCROLL="no"
> * * * * * * * * * * * * SHOWINTASKBAR="yes"
> * * * * * * * * * * * * SINGLEINSTANCE="yes"
> * * * * * * * * * * * * SYSMENU="yes"
> * * * * * * * * * * * * VERSION="1.0"
> * * * * * * * * * * * * WINDOWSTATE="maximized"/>
> * * * * </HEAD>
>
> * * * * <SCRIPT Language="VBScript">
> Dim arrUsers(1)
>
> ' Size window on load
> Sub Window_onLoad
> window.resizeTo 640, 480
> End Sub
>
> ' Cancel button
> Sub ExitProgram
> window.close()
> End Sub
>
> Sub btnComp_Click
>
> Set WshNetwork = CreateObject("Wscript.Network")
> strDN = WshNetwork.UserDomain
> arrUsers(0) = User1.value
> arrUsers(1) = User2.value
> For i = 0 To 1
> *If i = 0 Then
> * * * * * * * * * GetAllGroups(i)
> * * * * * * * * * UserGroup1.InnerHTML = sGroups
> *ElseIf i = 1 Then
> * * * * * * * GetAllGroups(i)
> * * * * * * * UserGroup2.InnerHTML = "Test 2"
> *End If
> *Next
> End Sub
>
> Function GetAllGroups(i)
> ' On Error Resume Next
> Set WshNetwork = CreateObject("Wscript.Network")
> * strDN = WshNetwork.UserDomain
> * sUser = arrusers(i)
> * Set objUser = GetObject("WinNT://" & strDN & "/" & sUser)
> * For Each oGroup In objUser.Groups
> * sGroups = sGroups & oGroup.Name & vbCrLf & "<br>"
> * Next
> * End Function
>
> * * * * </SCRIPT>
> * * * * <body STYLE="font:10pt arial; color:white;
> (background-color:Menu;
> color:MenuText;
> cursor:default">
> * * * * <p align=left><b>Group Migration Tool</b></font></p>
> *<table>
> *<tr>
> *<col align="left"></col>
> *<col width="160"></col>
> *<col align="left"></col>
> *<th><b>New User ID.</b></th>
> *<th>&nbsp;</th>
> *<th><b>Template User ID.</b></th>
> *</tr>
> *<tr>
> * <td><input type="text" name="User1" size=20><p align=left></td>
> *<td>&nbsp;</td>
> *<td><input type="text" name="User2" size=20><p align=left></td>
> * *</tr>
> * *<tr>
> * * * * <td><input type="button" value="Compare" name="btnComp"
> onClick="btnComp_Click" STyle='background-color: ButtonFace;'
> STyle='color:ButtonText;'></td>
> * * * * *<td><input id=runbutton type="button" value="Cancel"
> onClick="ExitProgram" STyle='background-color: ButtonFace;'
> STyle='color:ButtonText;'></td>
> * * * * * * </tr>
> * * * * * * *<p>
> <td><Span ID = "DataArea"</Span></td>
> <td><Span ID = "UserGroup1"</Span></td>
> <td><Span ID = "UserGroup2"</Span></td>
> </table>
> </body>
> </html>
>
> The code works in msgBox, and it writes "Test 2" in the UserGroup2
> InnerHTML as directed, it's just not writing to the InnerHTML that
> I've got set to populate with the variable..
There's nothing wrong with the InnerHTML. The problem is that your
function returns no value and Groups is not defined globally, so there
is nothing to write. One or the other thing is needed to send the
data back to be written. I would use the function return approach,
myself ...

Function GetAllGroups(i)
' On Error Resume Next
Set WshNetwork = CreateObject("Wscript.Network")
strDN = WshNetwork.UserDomain
sUser = arrusers(i)
Set objUser = GetObject("WinNT://" & strDN & "/" & sUser)
For Each oGroup In objUser.Groups
sGroups = sGroups & oGroup.Name & vbCrLf & "<br>"
Next
GetAllGroups = sGroups
End Function

Then, use the function thus ...

Sub btnComp_Click

' This is useless here ... Set WshNetwork = CreateObject
("Wscript.Network")
' same here ... strDN = WshNetwork.UserDomain
arrUsers(0) = User1.value
arrUsers(1) = User2.value
For i = 0 To 1
If i = 0 Then
UserGroup1.InnerHTML = GetAllGroups(i)
ElseIf i = 1 Then
' Huh? GetAllGroups(i)
UserGroup2.InnerHTML = "Test 2"
End If
Next
End Sub

It is clear to me that you don't understand the concept of 'scope' in
relationship to SUBs and Functions. Basically, variables have scopes
limited to where they are first defined in a script. If they are
first defined at the 'MAIN' level, they are global and can be accessed
in all subs and functions. However, if defined first in a function
(or using a DIM statement in the routine), then they only 'exist'
within that sub or function. Maybe you should download the WSH
documentation and read up on this.

WSH 5.6 documentation download (URL all one line)
http://www.microsoft.com/downloads/d...displaylang=en

Some of the WSH concepts don't apply to HTAs and it doesn't cover the
HTML stuff, but it should help understand the use of functions and
subs.

HTH,

Tom Lavedas
***********
My System SpecsSystem Spec