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

Dynmaic Drop Down List

Status
Not open for further replies.

secondreckoned

Technical User
Jan 20, 2004
35
CA
Hi,
I'm trying to create a three tier drop down list, the first dropdownlist will display type of job to be done ("WORKGROUPID"), once this is selected a list of Dispatch regions will appear ("DISPATCHREGIONID") which in turn will sort the third drop down list to show dispatch area's within each region ("DISPATCHAREAID"). I am able to get it to sort after I hit the form submit button, but not in the "onchange" event when I select workgroup or region. Here is the code, would appreciate any help as to why?
Thx.


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<%
Set objADOConn = Server.CreateObject("ADODB.Connection")
sConnect = "Driver={SQL Server};" & _
"Server=XXXXXX;" & _
"Database=XXXXXXX;" & _
"Uid=XXXXX;" & _
"Pwd=XXXXXX;"

objADOConn.ConnectionString = sConnect
objADOConn.Open

strWORKGROUPID = request.form("WorkGroup")
strDISPATCHREGIONID = Request.Form("DispatchRegion")
response.Write(strWORKGROUPID)
Sub fillWorkGroup()
Set WorkGroupRS = Server.CreateObject("ADODB.RecordSet")
WG = ("SELECT DISTINCT WORKGROUPID FROM tb_DispatchArea ORDER BY WORKGROUPID")
WorkGroupRS.Open WG, sConnect
do while not WorkgroupRS.EOF
if WorkGroupRS("WORKGROUPID") = strWORKGROUPID then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & WorkGroupRS("WORKGROUPID") & "</option>" & VBCRLF )
WorkGroupRS.MoveNext
loop
WorkGroupRS.Close
set WorkGroupRS=Nothing
End Sub

Sub fillDispatchRegion
Set DispatchRegionRS = Server.CreateObject("ADODB.RecordSet")
DR = ("SELECT DISTINCT DISPATCHREGIONID FROM tb_DispatchArea Where WORKGROUPID = '" & strWORKGROUPID & "' ORDER BY DISPATCHREGIONID")
DispatchRegionRS.Open DR, sConnect
If DispatchRegionRS.EOF Then
Response.Write("<option>No Regions Found</option>")
else
Response.Write("<option>Select Region Now</option>" & VBCRLF)
Do While Not DispatchRegionRS.EOF
If DispatchRegionRS("DISPATCHREGIONID") = strDISPATCHREGION Then
strSelected = "Selected"
Else
strSelected = ""
End If

Response.Write("<option" & strSelected & ">" & DispatchRegionRS("DISPATCHREGIONID") & "</option>" & VBCRLF )
DispatchRegionRS.MoveNext
loop
End If
DispatchRegionRS.Close
set DispatchRegionRS=Nothing
End Sub

Sub fillDispatchArea
Set DispatchAreaRS = Server.CreateObject("ADODB.RecordSet")
DA = ("SELECT DISTINCT DISPATCHAREAID FROM tb_DispatchArea WHERE DISPATCHREGIONID ='" &strDispatchRegion & "' ORDER BY DISPATCHAREAID")
DispatchAreaRS.Open DA, sConnect
do while not DispatchAreaRS.EOF
if DispatchAreaRS("DISPATCHAREAID") = DISPATCHAREAID then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & DispatchAreaRS("DISPATCHAREAID") & "</option>" & VBCRLF )
DispatchAreaRS.MoveNext
loop
DispatchAreaRS.Close
set DispatchAreaRS=Nothing
End Sub
%>
<head>
<title>Untitled Document</title>
</head>
<body>
<SCRIPT LANGUAGE=javascript>
<!--

function submitWG(){
var objForm = document.forms[0];
objForm.elements['DispatchRegion'].selectedIndex=0;
objForm.elements['DispatchArea'].selectedIndex = 0;
objForm.submit();
}
function submitDR(){
var objForm = document.forms[0];
objForm.elements['DispatchArea'].selectedIndex = 0;
objForm.submit();
}

function submitForm(){
var objForm = document.forms[0];
objForm.action = "drop1.asp"
return true;
}
//-->
</SCRIPT>

<table>
<form action="" method="post" id="form1" onSubmit="return submitForm()">
<tr>
<td align="center">
WorkGroup
</td>
<td align="center">
Dispatch Region
</td>
<td align="center">
Dispatch Area
</td>
</tr>
<tr>
<td align="center">
<select name="WorkGroup" onChange="submitWG()">
<% Call fillWorkGroup %>
</select>
</td>
<td align="center">
<select name="DispatchRegion" onChange="submitDR()">
<% Call fillDispatchRegion %>
</select>
</td>
<td align="center">
<select name="DispatchArea">
<% Call fillDispatchArea %>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit">
</td>
</tr>
</form>

</body>
</html>
 
After reading your code here is what I think happens.

The first time the page loads, there is a dropdown menu of all the workgroups with the first one showing. The other two menus do not have any items listed in them.

Click to select a workgroup and the page reloads. This time the workgroup menu is displayed with the selected workgroup showing, the menu of dispatch regions now has items and the first one is shown. The third menu does not have any items.

Click to select a dispatch region and the page reloads. This third time the workgroup and dispatch menus show the selected items and the dispatch area menu has items with the first one showing.

Whenever a menu has items the items are sorted by their ID.

You may wish to place some Response.Write statements inside the HTML to show the values for strWORKGROUPID and strDISPATCHREGIONID . Do they have the values you expect, or are they empty?

HTH.
 
rac2,
You're right, that is what I want to happen but the page isn't refreshing when I click and select a workgroup, I have to click on the submit button to reload the page instead of reloading on the "onChange" event. I suspect it has something to do with the Javascript, but not sure. When I response.write and hit submit it is giving me the appropriate selected values.
 
I usually use client side VBScript but shouldn't your javascript onChange call end with a ";"?



onChange="submitDR();">


Cheers

QatQat


Life is what happens when you are making other plans.
 
Try giving the submit input field a different name.

If you have Netscape or Firefox, take a look at the Javascript Console on the Tools->Web Development menu.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top