×
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!
  • Students Click Here

*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.

Students Click Here

VBScript / HTA - Drop Down Menu in form

VBScript / HTA - Drop Down Menu in form

VBScript / HTA - Drop Down Menu in form

(OP)
I hope you can help me.

Let me explain then.

I have three fields in this form. First is for a category, the second one is the subcategory (should be based on the first one), and the third one is the type (based on these previous two). Yet, there is also a fourth field, since we are talking about a incident form, that is the assignment group. Based on selected options on the first, second and third fields, the fourth (group) field is automatically populated with the destination group.

Today, I have this form only with blank fields. I can type anything I want on them. If the category, sub category, type, and group exists in the system, it will be accepted, the form will be submitted, and the incident will be created successfully. Otherwise, the incident will have missing fields or will be ambiguously created, if there is a typo or if there is any different word that is not in the system.

So, I need something like a dropdown menu in each first, second and third fields, and the fourth field must be displayed automatically based on the combined selection of these first three. Are you following me? Hope so!

Also, if possible, and preferably because it will be better for future updates, I wish to get these fields populated based on a external txt or a excel file, or else, if I incorporate these entries on this vbscript, it will become huge and maybe heavy.

Finally, each category (1st field) entry (in the excel/txt) should be associated to a ID. So should be the subcategory (2nd field), and the type (3rd field). Which means, a category name is displayed, but behind there is a ID associated, and when submitting the form, the ID is the one that will be sent to the system (hope I am being clear). So this information Category and ID, for e.g, will be available and will be collected by the form, from to the external file.

So, below is a video showing a working drop down menu incident form submition, just the way I am looking for. The file is in SWF (flash format), so you can open it with internet explorer or with flash player.

http://files.engineering.com/getfile.aspx?folder=9...

The actual and working VBscript is also available on the link below.

http://files.engineering.com/getfile.aspx?folder=2...

Thanks for all your help.

Best regards!

RE: VBScript / HTA - Drop Down Menu in form

Well,

Let's see if we can't get you at least started in the right direction.

First off let me suggest that if you place your data in a text file for easy editing and the fact that text files are easy to deal with in VBScript.
Since your data fields are all related to each other I would suggest that you put all related data in a single line of text but separate that data with a delimiter such as a slash and/or backslash. For example a line in your file might look like this: Apple/Jonathan\Juice.
I would then load the data into a dynamic array and then once it is in the array I would use the "split" command to extract the first field from the rest of the data and use that name to load your list box. For example the split command would use the "/" delimiter to extract the first field name and value from the other two fields.
Based on what you've said earlier there doesn't seem to be a need to display the other data in list boxes if fields 2 and 3 are dependent on field 1. If that's the case I would simply make the other fields a standard data field and gray out the box so you can't change the data once the user selects the appropriate value from the list box. This way the user can see what the values for fields 2 and 3 are but can't change them and can't select them. Since your data is already in an dynamic array you can loop thru the array to find the data for fields 2 and 3 based on what was selected in Field 1.

I know that was a lot to ingest but you have to start somewhere. Here's an HTA that I created for another purpose that I've cobbled up enough to show you some of the stuff related to loading a list box from an external file and also uses the split command as described above. There's a lot more in the HTA than you want (i.e. data entry, writing out a file based on data entered and encryption of a password field) but some of the stuff in there might otherwise be helpful if you've never written an HTA using Forms and boxes.....

Here's the copy of the Fruit.txt file:

Apple/Fuji\Juice
Orange/Valencia\Juice
Grapes/Concord\Juice
Pears/Bartlett\Juice

Here's the HTA

<HEAD>
<TITLE>Track My External IP Address</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff">


<FORM NAME="TrackMyIPForm">
<HTA:APPLICATION
ID = "TrackMyIP"
APPLICATIONNAME = "Track My External IP Address"
BORDER = "thick"
CAPTION = "yes"
SHOWINTASKBAR = "yes"
SINGLEINSTANCE = "yes"
SYSMENU = "yes"
WINDOWSTATE = "Normal"
SCROLL = "No"
SCROLLFLAT = "No"
VERSION = "1.0"
INNERBORDER = "yes"
SELECTION = "no"
MAXIMIZEBUTTON = "Yes"
MINIMIZEBUTTON = "Yes"
NAVIGABLE = "yes"
CONTEXTMENU = "yes"
BORDERSTYLE = "sunken"
>
<center><Table Border =2>
<Caption><Font color="#0000FF" face="arial" size="4pt"><B>Track My External IP Address</Font></B></Caption>
<Caption><Font color="#0000FF" face="arial" size="1pt"><B>Please make appropriate changes before pressing <U>START</U></Font></B>
<Caption><Font color="#0000FF" face="arial" size="1pt"><B>Note: Passwords are hidden and encrypted.</Font></B>
<TR><Center>
<TD><Font face="arial" size="2pt">ListBox:</TD>
<TD><Font face="arial" size="2pt"><select name="ListBoxData" size="1"></select></Font></TD>
</Center></TR>
<TR>
<TR><Center>
<TD><Font face="arial" size="2pt">Sender First Name:</TD>
<TD><Font face="arial" size="2pt"><INPUT TYPE="TEXT" SIZE=30 NAME="SenderFirstName"></TD>
</Center></TR>
<TR>
<TD><Font face="arial" size="2pt">Sender Last Name:</TD>
<TD><Font face="arial" size="2pt"><INPUT TYPE="TEXT" SIZE=30 NAME="SenderLastName"></TD>
</TR>
<TR>
<TD><Font face="arial" size="2pt">Send From Address:</TD>
<TD><Font face="arial" size="2pt"><INPUT TYPE="TEXT" SIZE=30 NAME="SendFromAddr"></TD>
</TR>
<TR>
<TD><Font face="arial" size="2pt">Send To Address:</TD>
<TD><Font face="arial" size="2pt"><INPUT TYPE="TEXT" SIZE=30 NAME="SendToAddr"></TD>
</TR>
<TR>
<TD><Font face="arial" size="2pt">SMTP Server:</TD>
<TD><Font face="arial" size="2pt"><INPUT TYPE="TEXT" Size=30 Name="SMTPServer"></TD>
</TR>
<TR>
<TD><Font face="arial" size="2pt">Sender User Name:</TD>
<TD><Font face="arial" size="2pt"><INPUT TYPE="TEXT" Size=30 Name="SendUserName"></TD>
</TR>
<TR>
<TD><Font face="arial" size="2pt">Sender User PSWD:</TD>
<TD><Font face="arial" size="2pt"><INPUT TYPE="PASSWORD" ID="PSWD1" SIZE=30 NAME = "SendUserPSWD1"></Font></TD>
</TR>
<TR>
<TD><Font face="arial" size="2pt">Confirm User PSWD:</TD>
<TD><Font face="arial" size="2pt"><INPUT TYPE="PASSWORD" ID="PSWD2" SIZE=30 NAME = "SendUserPSWD2"></Font></TD>
</TR>
<TR>
</Table></Center>
<FONT <Font color="#FF3333" size="1pt"><BR><B><Center><DIV ID=divProgress STYLE="font-size:30">...</B></DIV></Font></CENTER>
<P><Font face="arial" size="2pt"><Center><INPUT TYPE="BUTTON" SIZE=50 NAME="Execute" VALUE="Start" > <INPUT TYPE="BUTTON" SIZE=50 NAME="Terminate" VALUE="Stop" ></Font></CENTER>
</FORM>
</BODY>
</HTML>


<SCRIPT LANGUAGE="VBSCRIPT">
<!-- Option Explicit
'************************************************************************************
'* TrackMyIP.HTA *
'************************************************************************************
'* *
'* This is a sample HTA with embeded VBScript code. The intent is to show how an *
'* HTA can be coded with some input boxes and push buttons and a display area. *
'* *
'************************************************************************************
Dim fso,wshShell,OutputFileName,ExternalIPAddress,HeldExternalIP,CurrentPath,idTimer,_
VBScriptFileName,ArrFruitName(),FruitName
ReDim ArrFruitName(-1)
'************************************************************************************
'* This subroutine is executed when the HTA Windows is first opened. For the most *
'* part this is program initializaton stuff. *
'************************************************************************************
Sub window_OnLoad()
Dim form
Set form = document.TrackMyIPForm
ScreenHeight = screen.availHeight
ScreenWidth = screen.availWidth
WindowWidth = 420
WindowHeight = 520
WindowLeft = (ScreenWidth-WindowWidth)*.5
WindowTop = (ScreenHeight-WindowHeight)*.25
window.resizeto WindowWidth,WindowHeight
window.moveTo WindowLeft, WindowTop
form.SenderFirstName.value = ""
form.SenderLastName.value = ""
form.SendFromAddr.value = ""
form.SendToAddr.value = ""
form.SMTPServer.value = ""
form.SendUserName.value = ""
form.SendUserPSWD1.value = ""
form.SendUserPSWD2.value = ""
Set Fso = CreateObject("Scripting.FileSystemObject")
ExternalIPAddress = ""
HeldExternalIP = ""
CurrentPath = Fso.GetAbsolutePathName(".")
OutputFileName = CurrentPath & "\TrackMyIP.txt"
ListBoxFile = CurrentPath & "\Fruit.txt"
If Fso.FileExists(ListBoxFile) Then
set ostream = Fso.OpenTextFile(ListBoxFile)
do while not (ostream.atEndOfStream)
ReDim Preserve ArrFruitName(UBound(ArrFruitName) + 1)
ArrFruitName(UBound(ArrFruitName)) = ostream.ReadLine
FruitName = Split(ArrFruitName(UBound(ArrFruitName)),"/")
Set objOption1 = Document.createElement("OPTION")
objOption1.Text = FruitName(0)
objOption1.Value = FruitName(0)
Form.ListboxData.Add(objOption1)
Loop
End If
Call GetEmailInfo
If form.SendUserPswd1.value <> "" then
document.getElementByID("PSWD2").disabled = True
End If
if form.SenderFirstName.value = "" then
form.SenderFirstName.focus
else
form.Execute.focus
end if
End Sub

'************************************************************************************
'* This subroutine handles the encryption of any new password in the Password1 *
'* and changes the status of the Password2 field which is normally diabled. *
'************************************************************************************
sub SendUserPSWD1_OnChange()
Dim form
Set form = document.TrackMyIPForm
form.SendUserPSWD1.value = EnDeCrypt(form.SendUserPSWD1.value)
document.getElementByID("PSWD2").disabled = False
form.SendUserPSWD2.value = ""
form.SendUserPSWD2.focus
end sub

'************************************************************************************
'* This subroutine handles the encryption of any new password in the Password2 *
'* field handles the status of the Password2 field which is normally diabled. This *
'* subroutine also handles the situation where the two passwords don't match since *
'* the end user cannot see the password in clear text. *
'************************************************************************************
sub SendUserPSWD2_OnChange()
Dim form
Set form = document.TrackMyIPForm
form.SendUserPSWD2.value = EnDeCrypt(form.SendUserPSWD2.value)
if form.SendUserPSWD1.value <> form.SendUserPSWD2.value then
MsgBox "Passwords do not match. Plese re-enter both passwords"
form.SendUserPSWD1.value = ""
form.SendUserPSWD2.value = ""
form.SendUserPSWD1.focus
else
document.getElementByID("PSWD2").disabled = True
form.Execute.focus
end if
end sub

'************************************************************************************
'* This subroutine handles the events that take place when the end user presses the *
'* Execute button. In this subroutine the external file is written out. *
'************************************************************************************
Sub Execute_OnClick()
Dim form,Fso,oStream,WshShell,InputLine,InputArray,KeyWord,Command
set form = document.TrackMyIPForm
Set Fso = CreateObject("Scripting.FileSystemObject")
Set oStream = Fso.CreateTextfile(OutputFileName)
Set WshShell = CreateObject("WScript.Shell")
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
strSystemRoot = wshShell.ExpandEnvironmentStrings( "%SYSTEMROOT%" )
Call GetExternalIP
oStream.WriteLine "SenderFirstName:" & form.SenderFirstName.value
oStream.WriteLine "SenderLastName:" & form.SenderLastName.value
oStream.WriteLine "SendFromAddr:" & form.SendFromAddr.value
oStream.WriteLine "SendToAddr:" & form.SendToAddr.value
oStream.WriteLine "SMTPServer:" & form.SMTPServer.value
oStream.WriteLine "SendUserName:" & form.SendUserName.value
oStream.WriteLine "SendUserPSWD1:" & form.SendUserPSWD1.value
oStream.WriteLine "SendUserPSWD2:" & form.SendUserPSWD2.value
oStream.writeLine "ExternalIPAddress:" & ExternalIPAddress
ostream.close
End Sub

'************************************************************************************
'* This subroutine handles the events that take place when the end user presses the *
'* Stop button. In this subroutine simply closes the hypertext application. *
'************************************************************************************
Sub Terminate_OnClick()
self.close
End Sub


'************************************************************************************
'* Once the external email info is written to the TrackMyIP.txt file the first time *
'* it is re-used the next time the program is used and this get the old info. *
'************************************************************************************
Sub GetEmailInfo()
Dim form,Fso,oStream,InputLine,InputArray,KeyWord
set form = document.TrackMyIPForm
Set Fso = CreateObject("Scripting.FileSystemObject")
If Fso.FileExists(OutputFileName) Then
Set ostream = Fso.OpenTextFile(OutputFileName)
Do While not(ostream.atEndOfStream)
InputLine = ostream.ReadLine
if instr(inputline,":") then
InputArray = Split(InputLine,":")
Keyword = InputArray(0)
Select Case KeyWord
Case "SenderFirstName"
form.SenderFirstName.value = InputArray(1)
Case "SenderLastName"
form.SenderLastName.value = InputArray(1)
Case "SendFromAddr"
form.SendFromAddr.value = InputArray(1)
Case "SendToAddr"
form.SendToAddr.value = InputArray(1)
Case "SMTPServer"
form.SMTPServer.value = InputArray(1)
Case "SendUserName"
form.SendUserName.value = InputArray(1)
Case "SendUserPSWD1"
form.SendUserPSWD1.value = InputArray(1)
Case "SendUserPSWD2"
form.SendUserPSWD2.value = InputArray(1)
Case "ExternalIPAddress"
Case Else
End Select
End If
Loop
ostream.close
End If
End Sub


'************************************************************************************
'* This subroutine goes out to the Internet and graps the external IP address that *
'* is assigned to this computer. *
'************************************************************************************
Sub GetExternalIP()
Dim objIE
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "http://checkip.dyndns.org/"
' or "http://checkip.dyndns.org:8245/"
objIE.Visible = False
Do While objIE.Busy
idTimer = window.setTimeout("PausedSection", 1000, "VBScript")
Loop
ExternalIPAddress = objIE.Document.body.innerhtml
ExternalIPAddress = Trim(Mid(ExternalIPAddress,inStr(ExternalIPAddress,":") + 2))
divProgress.InnerText = ExternalIPAddress
Set objIE = Nothing
End Sub

'************************************************************************************
'* HTA's don't have a SLEEP function capability so a Timer is needed to control *
'* the wait function. Each time the time is set it must be cleared *
'************************************************************************************
Sub PausedSection
window.clearTimeout(idTimer)
End Sub

'************************************************************************************
'* Encrypts/decrypts the SendUserPSWD value so then when the TrackMyIP.TXT file is *
'* saved the information is not shown in clear text. *
'************************************************************************************
Function EnDeCrypt(plaintxt)
Dim sbox(255), key(255), a, b, h, i, j, k, cipherby, cipher, temp, tempswap, intLength, psw
i = 0
j = 0
psw = "LswPPlKXQJ"
intLength = Len(psw)
For a = 0 To 255
key(a) = Asc(Mid(psw, (a Mod intLength) + 1, 1))
sbox(a) = a
Next
b = 0
For a = 0 To 255
b = (b + sbox(a) + key(a)) Mod 256
tempswap = sbox(a)
sbox(a) = sbox(b)
sbox(b) = tempswap
Next
For h = 1 To Len(plaintxt)
i = (i + 1) Mod 256
j = (j + sbox(i)) Mod 256
temp = sbox(i)
sbox(i) = sbox(j)
sbox(j) = temp
k = sbox((sbox(i) + sbox(j)) Mod 256)
cipherby = Asc(Mid(plaintxt, h, 1)) Xor k
cipher = cipher & Chr(cipherby)
Next
EnDeCrypt = cipher
End Function
-->
</SCRIPT>
</BODY>
</HTML>




RE: VBScript / HTA - Drop Down Menu in form

(OP)
Are you sure?!

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! Already a Member? Login

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