Click to See Complete Forum and Search --> : Triple Dependent List boxes


simflex
10-03-2003, 10:31 AM
Awhile back, I had wanted to know if anyone could assist me with a triple dependent list box.
Here is the code.
Though this code is for 3 dependent list boxes, it can be extended to more than 3.
I still have a little problem with it.
It pulls data from the db and populates the 2nd and 3rd boxes automatically but problem is it pulls wrong data.
I can't for the life of me figure out why it is doing that.
For instance, if I want to pull the name of an emp and the division he/she works in, let's assume the emp's name is John Doe in division called 'HR' and his org is 2200.
When I pull the name, it pulls the correct org but the org pulls a different division.
Can someone please take a look at the code and tell me what could be causing this problem?
This will really be appreciated.
Here is the entire "real" code:

<%@ Language = VBScript %>
<%Option Explicit%>
<%Response.Buffer = True%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<%
dim strConnectString, objConnection, strName, strOrg, strDivision, objRS, strSelected

'set connection strings for entire application
strConnectString = "dsn=safety"

if not IsObject("ojbConnection") then
set objConnection=Server.CreateObject("ADODB.Connection")
objConnection.ConnectionTimeout = 15
objConnection.CommandTimeout = 10
objConnection.Mode = 3 'adModeReadWrite
if objConnection.state = 0 then
objConnection.Open strConnectString
end if
end if

strName = Request.Form("fullname")
strOrg = Request.Form("Org")
strDivision = Request.Form("Division")

sub makeName()
if not isObject("objRS") then
set objRS=Server.CreateObject("ADODB.RecordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT fname+' '+lname as fullname FROM theEmp ORDER BY fullname",objConnection,3,3
Response.Write("<option></option>" & VBCRLF )
do while not objRS.EOF
if objRS("fullname") = strName then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("fullname") & "</option>" & VBCRLF )
objRS.MoveNext
loop
objRS.Close
set objRS=Nothing
end sub

sub makeOrg()
if strName <> "" then
if not isObject("objRS") then
set objRS=Server.CreateObject("ADODB.RecordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT Org FROM theEmp WHERE fname+' '+lname = '" & strName & "' ORDER BY Org",objConnection,3,3
if objRS.eof then
Response.Write("<option>No Orgs Found</option>")
else

do while not objRS.EOF
if objRS("Org") = strOrg then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("Org") & "</option>" & VBCRLF )
objRS.MoveNext
loop
end if
objRS.Close
set objRS=Nothing
else
Response.Write("<option>Select a Name First</option>")
end if
end sub

sub makeDivision()
if strOrg <> "Select a Name First" AND strOrg <> "Select Org Now" AND strOrg <>"" then
if not isObject("objRS") then
set objRS=Server.CreateObject("ADODB.RecordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT Division FROM theEmp WHERE Org = '" & strOrg & "' ORDER BY Division",objConnection,3,3
if objRS.eof then
Response.Write("<option>No Divisions Found</option>")
else
do while not objRS.EOF
if objRS("Division") = strDivision then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("Division") & "</option>" & VBCRLF )
objRS.MoveNext
loop
end if
objRS.Close
set objRS=Nothing
else
Response.Write("<option>Select an Org First</option>")
end if
end sub
%>

<SCRIPT LANGUAGE=javascript>
<!--

function submitName(){
var objForm = document.forms[0];
objForm.elements['Org'].selectedIndex=0;
objForm.elements['Division'].selectedIndex = 0;
objForm.submit();
}
function submitOrg(){
var objForm = document.forms[0];
objForm.elements['Division'].selectedIndex = 0;
objForm.submit();
}

//-->
</SCRIPT>

</HEAD>
<BODY>
<FORM action="MultiSelect.asp" method=POST id=form1 name=form1>
<SELECT name="fullname" onChange="submitName()">
<%call makeName%>
</SELECT><br>
<SELECT name="Org" onChange="submitOrg()">
<%call makeOrg%>
</SELECT><br>
<SELECT name="Division">
<%call makeDivision%>
</SELECT><br>

<p><INPUT type="submit" value="Submit" id=submit1 name=submit1></p>
</FORM>
</BODY>
<%
objConnection.Close
set objConnection = Nothing
%>

</HTML>

simflex
10-04-2003, 07:55 AM
Dave Clark, whatever happened to you!