Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate values in a list box dynamically in HTA 1

Status
Not open for further replies.

tulsantide

Technical User
Jun 1, 2015
21
US
Hi,

I'm trying to populate values in a list box dynamically on loading HTA. I have the following code, which is giving me an error. Please let me know if I'm doing anything wrong. Thanks!

#######################################################################
<html>

<head>

<title>Users</title>


<HTA:APPLICATION


APPLICATIONNAME=”Users”

SCROLL=”yes”

SINGLEINSTANCE=”yes”

WINDOWSTATE=”maximize”

>

<SCRIPT Language=”VBScript”>


Sub Users_Onload()

a = Array("user1","user2","user3","user4")


For Each User In a

Set objOption = Document.createElement(“OPTION”)

objOption.Text = User

objOption.Value = User

Users.Add(objOption)

Next

End Sub


</SCRIPT>

</head>


<body onload="Users_Onload">

<select id="Users" size=”4" name=Users>

</select>

</body>

</html>

 
And the error that you are getting is?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Chris,
I'm getting the following error.

Error:'Users_Onload' is undefined.

Thanks
 
If you want to run a javascript function from onload, you specify onload="javascript:functionname". So how about onload="VBScript:Users_Onload"?

Bye, Olaf.
 
VBScript and events work much diffferent than with Javascript, it seems. Simply name your Sub Window_Onload and don't specify the body onload at all...

Code:
<!doctype html>
<html>
<head>
<title>Users</title>
<HTA:APPLICATION
APPLICATIONNAME="Users"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="maximize"
>

<SCRIPT Language="VBScript">
Sub Window_Onload()
  a = Array("user1","user2","user3","user4")
  For Each User In a
    Set objOption = Document.createElement("OPTION")
    objOption.Text = User
    objOption.Value = User
    Users.Add(objOption)
  Next
End Sub
</SCRIPT>
</head>

<body>
<select id="Users" size="4" name=Users>
</select>
</body>
</html>

You are better looking for a VB Script forum to get this forward. HTA is very Windows and MS specific and while it uses HTML it's not really the core topic here.

Bye, Olaf.
 
Thanks! Olaf and all.
It worked after following Olaf's suggestion.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top