Click to See Complete Forum and Search --> : Populating a drop box through another


minority
07-20-2005, 08:01 AM
this one got me stumped. I need some one with a brain!!

ok what i am trying to do.

Firstly i have this upload document which hass a drop down populated by Document_type table what i want is when they select something from here if it has a Sub category then populate the other box with the relevent sub categories if possible.

Yes it is a yes/no column buntine lol.

the code i have so far is bellow i aint a clue what to do to get this to work.
<!--#include file="../testsecurity2.asp"-->
<% levelcheck(2)%>
<%
'Sample file Field-SaveAs.asp
'Store extra upload info to a database
' and file contents to the disk
Server.ScriptTimeout = 5000

'Create upload form
'Using Huge-ASP file upload
'Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")
'Using Pure-ASP file upload
Dim Form: Set Form = New ASPForm %><!--#INCLUDE file="_upload.asp"--><%


Server.ScriptTimeout = 1000
Form.SizeLimit = &HA00000'10MB

'was the Form successfully received?
Const fsCompletted = 0

If Form.State = fsCompletted Then 'Completted

'Create destination path+filename for the source file.
Dim DestinationPath, DestinationFileName
DestinationPath = "C:\Intranet\qms\upload\"
DestinationFileName = DestinationPath & Form("SourceFile").FileName


'Open recordset to store uploaded data
Dim RS: Set RS = OpenUploadRS

'Store extra info about upload to database
RS.AddNew
RS("Date") = Now()
RS("Doc_Name") = Form("SourceFile").FileName
RS("Version") = Form.Texts.Item("Version")
RS("Dept_ID") = Form.Texts.Item("Dept")
RS("Doc_Type_ID") = Form.Texts.Item("DocType")
RS("From") = Form("SourceFile").FilePath
RS("Link") = DestinationFileName
RS("DataSize") = Form("SourceFile").Length
'...
RS.Update

Response.write "<br>Source file names:"
Dim Field: For Each Field in Form.Files.Items
Response.write "<br>&nbsp;" & Field.FileName
Next
'{b}Save file to the destination
Form("SourceFile").SaveAs DestinationFileName
'{/b}

response.write "<Font color=green><br>SourceFile was saved as " & DestinationFileName
response.write "<br>See ListFiles table in " & Server.MapPath("upload.mdb") & " database.</Font>"
Response.Redirect("../index.asp")
ElseIf Form.State > 10 then
Const fsSizeLimit = &HD
Select case Form.State
case fsSizeLimit: response.write "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
case else response.write "<br><Font Color=red>Some form error.</Font><br>"
end Select
End If'Form.State = 0 then

Function OpenUploadRS()
Dim RS : Set RS = CreateObject("ADODB.Recordset")

'Open dynamic recordset, table Upload
RS.Open "Document", GetConnection, 2, 2

Set OpenUploadRS = RS
end Function

Function GetConnection()
dim Conn: Set Conn = CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.open "Data Source=C:\Intranet\qms\database\qrm.mdb;User Id=admin;Password=;"
set GetConnection = Conn
end function
%>
</head> <form method=post ENCTYPE="multipart/form-data">
<body onLoad="MM_preloadImages('/images/nav/home_r.gif','/images/nav/applications_r.gif','/images/nav/products_r.gif','/images/nav/software_r.gif','/images/nav/support_r.gif','/images/nav/developments_r.gif','/images/nav/investor_r.gif','/images/nav/locations_r.gif')">

<!--#include file="../../include/docmenu.asp"--></td>
<td width="721">
<!-- PAGE CONTENT START -->
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top"> <table width ="100%">
<tr>
<td width = "3%"></td>
<td width = "47%"><b>
<h1><u>Intranet Administration</u></h1>
</b></td>
<td width = "50%"></td>
</tr>
</table>
<table width ="100%">
<tr>
<td width = "5%"></td>
<td width = "44%"><b>
<h2>Delete Document</h2>
</b></td>
<td width = "51%"></td>
</tr>
</table></td>
</tr>
<tr>
<td> <table width ="100%">
<tr>
<td width ="10%"></td>
<td width ="15%"> File to upload</td>
<td width = "30%"><input type="file" name="SourceFile"></td>
</tr>
<tr>
<td>
<tr>
<td width ="10%"></td>
<td width ="15%">Version</td>
<td width ="30%"><input ="text" name="Version"></td>
</tr>
<tr>
<td width ="10%"></td>
<td width ="15%">Department
<% Dim strCon
Dim strSQLDocType, strSQLDept
Set rsDocType = Server.CreateObject("ADODB.Recordset")
Set rsDept = Server.CreateObject("ADODB.Recordset")
strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Intranet\qms\database\qrm.mdb;User Id=admin;Password=;"
strSQLDocType = "SELECT Doc_Type_ID, Type_Name FROM Document_Type"
strSQLDept = "SELECT Dept_ID, Dept_Name FROM Department"
rsDocType.Open strSQLDocType, strCon
rsDept.Open strSQLDept, strCon
%></td>
<td width ="30%"> <select name="Dept">
<%
Do until rsDept.EOF
Response.Write("<option value=""" & rsDept("Dept_ID") & """ > " & rsDept("Dept_Name") & "</option>" & vbCrLf)
rsDept.MoveNext()
loop
%>
</select> <%
rsDept.Close
Set rsDept = Nothing
%></td>
</tr>
<tr>
<td width ="10%"></td>
<td width ="15%">File Type</td>
<td width ="30%"> <select name="DocType">
<%
Do until rsDocType.EOF
Response.Write("<option value=""" & rsDocType("Doc_Type_ID") & """ > " & rsDocType("Type_Name") & "</option>" & vbCrLf)
rsDocType.MoveNext()
loop
%>
</select> <%
rsDocType.Close
Set rsDocType = Nothing
Set adoCon = Nothing
%></td>
</tr>
</table><br>
<table width ="85%">
<tr>
<td width="25%"></td>
<td width ="20%"><input type="submit" Name="Action" value="Upload File"></td>
<td width ="5%"></td>
<td width ="30%"><input type="submit" Name="reset" value="Reset"> </td>
</tr>
</table></form></td>
</tr>
</table>
<!-- PAGE CONTENT END -->
</td>
<td width="17">
<!-- RIGHT MENU START -->
<!-- RIGHT MENU END -->
</td>
</tr>
<tr align="left" valign="top">
<td bgcolor="#0c66aa"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr align="left" valign="top">
<td bgcolor="#0c66aa"></td>
<td align="center" class="copyright"></td>
<td></td>
</tr>
<tr align="left" valign="top">
<td bgcolor="#0c66aa">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="topTile" >
<tr>
<td width="145" align="left" valign="top" class="bodyCopy"><img src="../../Images/logo1bottom.GIF" alt="Sondex" width="145" height="10" border="0"></td>
<td width="344" align="left" valign="top" class="bodyCopy"><img src="../../Images/logo3bottom.GIF" alt="" width="344" height="10" border="0"></a></td>
<td width="408" align="left" valign="top"><img src="../../Images/logoendbottom.GIF" alt="" width="344" height="10" border="0"></td>

<td width="100%" align="left" valign="top"><img src="../../Images/logoend_Revisedbottom.GIF" alt="" width="104" height="10" border="0"></td>
</tr>
</table>
</body>
</html>


Any help would be greatful especially since i need pretty much guided through it.

genius
07-20-2005, 11:17 PM
hi.........
i m sending my code change it as per ur need.if any doubt ur most welcome.

best of luck...........


<%
'declare some variables
dim objRS, strSQL, arrRS,conn

'create recordset object
set conn = server.CreateObject ("adodb.connection")
conn.Open "dsn=eximmail"
Set objRS = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT distinct z.location_id,z.location, y.company_id,y.company_name FROM (appointment_detail AS x INNER JOIN location_table AS z ON x.location_id = z.location_id) INNER JOIN company AS y ON x.company_id=y.company_id WHERE x.expiry_date >=date() ORDER BY z.location ,y.company_name"
objRS.Open strSQL,conn
'build an array from the recordset using GetRows
arrRS = objRS.GetRows
'close the recordset
objRS.close
set objRS = nothing

'each of the fields from the sql statement will be referenced in the function call
'by their numeric position, starting from 0, so in this example:
'countryID = 0
'countryName = 1
'cityID = 2
'cityName = 3
%>


<style type="text/css">
.width150 {
width: 150px;
}
</style>
<form id="testform" method="post">
<%= buildLinkedList("listCountry",0,1,1,"Select a location","width150","listCity",2,3,1,"Select a company","width150") %>
</form>
<%
function buildLinkedList(list1name,list1value,list1text,list1size,list1prompt,list1class,list2name,list2value ,list2text,list2size,list2prompt,list2class)
dim strList1, i, strValue, strAssocArr, strAssocArrElem, strList2, strArray, strFunctions
'build the output for the first list
strList1 = "<select class='" & list1class & "' name='" & list1name & "' size='" & list1size & "' onchange='getList2(this);'>" & VbCrLf
strList1 = strList1 & "<option value='' selected='selected'>" & list1prompt & "</option>" & VbCrLf
for i = 0 to uBound(arrRS,2)
if arrRS(list1text,i) <> strValue then
strValue = arrRS(list1text,i)
strList1 = strList1 & "<option value='" & arrRS(list1value,i) & "'>"
strList1 = strList1 & arrRS(list1text,i) & "</option>" & VbCrLf
if len(strAssocArr) > 0 then
strAssocArr = left(strAssocArr, len(strAssocArr) - 3) & VbCrLf & ");" & VbCrLf
end if
strAssocArr = strAssocArr & "assocArray[""" & list1name & "=" & arrRS(list1value,i) & """] = new Array(" & VbCrLf
strAssocArr = strAssocArr & """"",""" & list2prompt & """," & VbCrLf
end if
strAssocArrElem = """" & arrRS(list2value,i) & """, """ & arrRS(list2text,i) & """," & VbCrLf
strAssocArr = strAssocArr & strAssocArrElem
next
strList1 = strList1 & "</select>" & VbCrLf

'build the output for the second list
strList2 = "<select class='" & list2class & "' name='" & list2name & "' size='" & list2size & "'>" & VbCrLf
strList2 = strList2 & "<option value=''>&nbsp;</option>" & VbCrLf
strList2 = strList2 & "</select>" & VbCrLf

'build the associative array to populate list 2
strAssocArr = mid(strAssocArr, 1, len(strAssocArr)-3) & ");"
strArray = "<script type='text/javascript' language='javascript'>" & VbCrLf
strArray = strArray & "var assocArray = new Object();" & VbCrLf
strArray = strArray & strAssocArr & VbCrLf

'build the javascript functions to operate the listboxes
strFunctions = "function getList2(listOptions){" & VbCrLf
strFunctions = strFunctions & " var thisform = listOptions.form;" & VbCrLf
strFunctions = strFunctions & " clearDropDown(thisform." & list2name & ");" & VbCrLf
strFunctions = strFunctions & " var newvalue = listOptions.name + ""="" + listOptions.options[listOptions.selectedIndex].value;" & VbCrLf
strFunctions = strFunctions & " fillDropDown(thisform." & list2name & ", newvalue); // fill the 2nd dropdown options" & VbCrLf
strFunctions = strFunctions & "}" & VbCrLf
strFunctions = strFunctions & "function clearDropDown(listOptions){" & VbCrLf
strFunctions = strFunctions & " for (var i = listOptions.options.length - 1; i >= 0; i--){" & VbCrLf
strFunctions = strFunctions & " listOptions.options[i] = null;" & VbCrLf
strFunctions = strFunctions & " }" & VbCrLf
strFunctions = strFunctions & " listOptions.selectedIndex = -1;" & VbCrLf
strFunctions = strFunctions & "}" & VbCrLf
strFunctions = strFunctions & "function fillDropDown(listOptions, vValue){" & VbCrLf
strFunctions = strFunctions & " if (vValue != """" && assocArray[vValue]){" & VbCrLf
strFunctions = strFunctions & " var arrX = assocArray[vValue];" & VbCrLf
strFunctions = strFunctions & " for (var i = 0; i < arrX.length; i = i + 2){" & VbCrLf
strFunctions = strFunctions & " listOptions.options[listOptions.options.length] = new Option(arrX[i + 1], arrX[i]);" & VbCrLf
strFunctions = strFunctions & " }" & VbCrLf
strFunctions = strFunctions & " } else listOptions.options[0] = new Option("""", """");" & VbCrLf
strFunctions = strFunctions & "}" & VbCrLf
strFunctions = strFunctions & "</script>" & VbCrLf

buildLinkedList = strList1 & VbCrLf & strList2 & VbCrLf & strArray & VbCrLf & strFunctions & VbCrLf
end function
%>

minority
07-21-2005, 02:15 AM
Cheers I will see what i can do with it.

Lol see if my limited knowledge will manage it.

I aint went throught it totally yet but will it allow the text fields that i have to be stored as with my experiements i have always lost the data inside them.