INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Populate values in a list box dynamically in HTA

Populate values in a list box dynamically in HTA

(OP)
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>

RE: Populate values in a list box dynamically in HTA

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

RE: Populate values in a list box dynamically in HTA

(OP)
Chris,
I'm getting the following error.

Error:'Users_Onload' is undefined.

Thanks

RE: Populate values in a list box dynamically in HTA

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

Bye, Olaf.

RE: Populate values in a list box dynamically in HTA

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.

RE: Populate values in a list box dynamically in HTA

(OP)
Thanks! Olaf and all.
It worked after following Olaf's suggestion.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close