Advertisement

05.20.2008 at 08:02AM PDT, ID: 23417419
[x]
Attachment Details

Populate dependant dropdowns from database tables

Asked by IntercareSupport in Active Server Pages (ASP), JavaScript

Tags: ASP

hello ee,
I'm having trouble with dependant dropdowns. I have a dropdown for location & another for staff member. Based on the location the user chooses, i would like those staff members to show specific to that location. I can get it to work if i hardcode an javascript array example, but due to that a fact that users can edit those tables i have a table for both the location & staff members that changes, so i guess my quetion is how do i get this all to work by looping through a javascript array with asp? Here is my scenario.

tbl_Location
-----Location_Name
tbl_Staff
tbl_Location
-----Staff_Name
-----Location_Name


Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
<script>
var BGArray = new Array ("bg staff 1", "bg staff 2", "bg staff 3")
var BHArray = new Array ("bh staff 1", "bh staff 2", "bh staff 3")
var ECArray = new Array ("ec staff 1", "ec staff 2", "ec staff 3")
var HDArray = new Array ("hd staff 1", "hd staff 2", "hd staff 3")
var PMArray = new Array ("pm staff 1", "pm staff 2", "pm staff 3")
var OtherArray = new Array ("Other")
 
function updateList(theForm, catName, subjListLength)
{
	for (var i=subjListLength + 1 ; i > 0 ; i-- )
	{
		theForm.Staff.options[i] = null
	}
	if( catName == "None"){
		var option0 = new Option("- Staff -", "None")
	}
	else{
		eval('var option0 = new Option("- Staff -", "None")')
	}
	NSL=0
	if (catName != "None") {
		eval("var NewSource = " + catName +"Array")
		NSL = NewSource.length
		for(var L = 0; L < NSL + 1; L++) {
			eval("var option" + [L + 1] + " = new Option(" + '"' + NewSource[L] + '", "' + NewSource[L] + '")') 
		}
	}
	for (var i=0; i < NSL + 1; i++) {
		eval("theForm.Staff.options[i]=option" + i)
		if (i==0) {
			theForm.Staff.options[i].selected=true
		}
	}
}
</script>
<form name='frm_sample' id='frm_sample' action='Process.asp' method='post'>
	<p>Location:
		<select name='Location' size="1" onChange="updateList(this.form, this.options[selectedIndex].value, this.form.Staff.length);">
			<option value="None" Selected >- Please Choose -</option>
			<option value="BG">Bgr</option>
			<option value="BH">Btn</option>
			<option value="EC" >Eau</option>
			<option value="HD" >Hld</option>
			<option value="PM" >Plm</option>
			<option value="Other" >Otr</option>
		</select>
	</p>
	<p>Staff:
		<select name="Staff" id="Staff">
			<option value="None" SELECTED>- Staff -</option>
		</select>
	</p>
</form>
[+][-]05.20.2008 at 08:26AM PDT, ID: 21607073

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 08:38AM PDT, ID: 21607218

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 09:31AM PDT, ID: 21607828

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Active Server Pages (ASP), JavaScript
Tags: ASP
Sign Up Now!
Solution Provided By: Bane83
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.20.2008 at 09:35AM PDT, ID: 21607875

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 09:49AM PDT, ID: 21608003

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628