[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

HTA Populate a Combo Box based on the value of another

Posted on 2009-04-21
4
Medium Priority
?
1,624 Views
Last Modified: 2012-05-06
I have a Combo Box with the values "07, 08, 09, 10, 11, 12"
When a value in the first combo box is selected, I want the values of the second combo box to be "B1, B2, B3, B4, B5, F1, F2, F3, F4, F5, S1, S2, S3, S4, S5, T1, T2, T3, T4, T5", preceeded by the value of the first combo box and a hypen. Eg 10-S4 or 12-T1

This will be used in a HTA. Any help much appreciated :-)
0
Comment
Question by:churchlandsshs
  • 2
  • 2
4 Comments
 
LVL 9

Expert Comment

by:dan_neal
ID: 24193501
I've worked up some sample code that should help you out.  Of course the names/ids are completely up to you just make sure to change in both the HTML and the VBScript.  You could also call the sub from a startup routine to fill the list just so it doesn't appear blank.

'======Add this to your vbscript section=======
secBoxArray = array("B1", "B2", "B3", "B4", "B5", "F1", "F2", "F3", "F4", "F5", "S1", "S2", "S3", "S4", "S5", "T1", "T2", "T3", "T4", "T5")
sub PopulateSecondBox()
	dim i, firstBoxValue
	firstBoxValue = combo1.value
	combo2.options.length = 0
	for i = 0 to ubound(secBoxArray)
		set opt = document.createelement("OPTION")
		opt.value = firstBoxValue & "-" & secBoxArray(i)
		opt.text = firstBoxValue & "-" & secBoxArray(i)
		combo2.add opt
		set opt = nothing
	next
end sub
 
========Adjust your HTML to the following=======
<select name="combo1" id="combo1" onchange="PopulateSecondBox">
<!--of course you options would go here for box 1-->
</select>
 
<select name="combo2" id="combo2"></select>

Open in new window

0
 

Author Comment

by:churchlandsshs
ID: 24200568
Hi dan_neal,
this works well, however the value of my options in combo1 are different from what the text is. Is it possible to have combo2 use the text from combo1, rather than the value?
Eg <option value="TAG10">07</option>
I don't want combo2 to display "TAG10-B1", but instead "07-B1"
any help much appreciated :-)
0
 
LVL 9

Accepted Solution

by:
dan_neal earned 2000 total points
ID: 24201056
Absolutely.  See below.
'======Add this to your vbscript section=======
secBoxArray = array("B1", "B2", "B3", "B4", "B5", "F1", "F2", "F3", "F4", "F5", "S1", "S2", "S3", "S4", "S5", "T1", "T2", "T3", "T4", "T5")
sub PopulateSecondBox()
	dim i, firstBoxValue
         'line changed here to use text of selected option instead of value
	firstBoxValue = combo1(combo1.selectedindex).text
	combo2.options.length = 0
	for i = 0 to ubound(secBoxArray)
		set opt = document.createelement("OPTION")
		opt.value = firstBoxValue & "-" & secBoxArray(i)
		opt.text = firstBoxValue & "-" & secBoxArray(i)
		combo2.add opt
		set opt = nothing
	next
end sub
 
========Adjust your HTML to the following=======
<select name="combo1" id="combo1" onchange="PopulateSecondBox">
<!--of course you options would go here for box 1-->
</select>
 
<select name="combo2" id="combo2"></select>

Open in new window

0
 

Author Closing Comment

by:churchlandsshs
ID: 31572608
Very good :-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Suggested Courses

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question