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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate combo dependant on another

Status
Not open for further replies.

Syerston

Programmer
Jun 2, 2001
142
GB
Hi Everybody

I have been struggling to find a way to populate a combo box dependant on a user selection on a previous combo box.

Could someone please give me some guidance. I would prefer to use VBScript if possible.

Many Thanks

John
 
You could use javascript to populate a second menu based on the choice made in the first menu:


 
I've never used Java before. Would anyone have a very simplistic example of how to do this, or be able to give me a hyperlink to one.

John
 
javascript not java - are you populating dropdowns from a database?

If so you could submit onchange and popluate the second drop down from the database:

The javascript code I can send you if you want to do all the work in the client.
 
The one i use is like the one sjravee describes

<script language=&quot;javascript&quot; src=&quot;jscripts/_make_businessdropdowns.js&quot;></script>
<script language=&quot;javascript&quot;>
function set_business_function(ranges, values) {
selectedIndex = 0;
var dropDown;
dropDown = document.f.businessfunction;
if (dropDown) {
dropDown.length = 0;
for(index=0; index<ranges.length; index++) {
dropDown[index] = new Option(ranges[index],values[index], false, false);
}
dropDown.options[selectedIndex].selected = true;
}
}
</script>

the function is called by onchange in the master select:
<select name='busunit' onChange=&quot;set_business_function(_business_unit_function[this.selectedIndex], _business_unit_function_number[this.selectedIndex]);&quot; >

child select:
<select name=&quot;businessfunction&quot;>
<option value=&quot;1000&quot;>
</option>
</select>

and uses the _make_businessdropdowns.js which I build from a database and is a 2d array but which looks like:

_business_unit_function = new Array();
_business_unit_function_number = new Array();

// defautl menu structure
_business_unit_function[0] = new Array('All or Select A Business Unit Community','');
_business_unit_function_number[0] = new Array(1000,1000);

_business_unit_function[1] = new Array('All or Select A Business Unit Community','Retail Wide News');
_business_unit_function_number[1] = new Array(1000,1000);

_business_unit_function[2] = new Array('All or Select A Business Unit Community','Indirect Channels');
_business_unit_function_number[2] = new Array(1000,1);

_business_unit_function[3] = new Array('All or Select A Business Unit Community','BT Openworld');
_business_unit_function_number[3] = new Array(1000,1000);

_business_unit_function[4] = new Array('All or Select A Business Unit Community','Northern Ireland','Scotland','North East Region','North West Region','Yorkshire & Humberside Region','West Midlands Region','East Midlands Region','East of England Region','London','South East Region','South West Region','Wales');
_business_unit_function_number[4] = new Array(1000,2,3,4,5,6,7,8,9,10,11,12,13);
 
Thanks for all your help.

Would mit99mh be able to post or send me the copy of the code. I am populating the boxes from a database.

Thanks

john.lamont@nihe.gov.uk

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top