MetroToday
MIS
I have two pieces of code. Both are used to populate a drop down list box dynamically. However I would like to integrate them into one.
First part of code:
There are two dropdown boxes which are linked to each other. That means if I select a value from the first then the second one populates with values accordingly.
Second Part of code
If from the previous page a user enters a barcode ID, the on the next page the two drop down boxes should populate with the correct data.
I am having trouble combining both the codes.
Here they are.
For first Dropdown box: (is accesed through the include command)
<%
Set oTmp = Server.CreateObject("ADODB.Recordset"
oTmp.Open "SELECT * FROM ctrldept", "DSN=storage"
Do While Not oTmp.EOF
Response.Write("<OPTION VALUE=""" & oTmp("ctrlDeptID" & """ "
If Not oRS.EOF And Not oRS.BOF Then
If oRS("ctrlDeptID" = oTmp("ctrlDeptID" Then
Response.Write("SELECTED "
End If
End if
Response.Write(">"
Response.Write(oTmp("department" & " - " & oTmp("deptid" & " "
Response.Write("</OPTION>"
oTmp.MoveNext
Loop
oTmp.Close
Set oTmp = Nothing
%>
For second Dropdown box: (is accesed through the include command)
<%
Set oTmp = Server.CreateObject("ADODB.Recordset"
oTmp.Open "SELECT * FROM ctrlDocs", "DSN=storage"
Do While Not oTmp.EOF
Response.Write("<OPTION VALUE=""" & oTmp("ctrlDocsID" & """ "
If Not oRS.EOF And Not oRS.BOF Then
If oRS("ctrlDocsID" = oTmp("ctrlDocsID" Then
Response.Write("SELECTED "
End If
End if
Response.Write(">"
Response.Write(oTmp("Doctype" & " - " & oTmp("DocID" & " "
Response.Write("</OPTION>"
oTmp.MoveNext
Loop
oTmp.Close
Set oTmp = Nothing
%>
Code for auto populating both the drop down boxes and where the second dropdown box adjusts it self based on the selection of the first drop downbox.
dim selectedDept
If Request("ctrlDeptID" = "" then
selectedDept = "0"
Else
selectedDept = Request("ctrlDeptID"
end if
<% <td width="22%"><select size="1" name="ctrlDeptID" OnChange="frmtypes.submit();">
Set conn = Server.CreateObject("ADODB.Connection"
conn.Open "DSN=storage"
Set rs = conn.Execute("SELECT * FROM ctrldept"
Do While Not rs.EOF %>
<OPTION VALUE="<%= RS("ctrlDeptID" %>" <% If RS("ctrlDeptID" = CInt(selectedDept) Then Response.Write("SELECTED"%>> <%= RS("department" %> - <%= RS("deptid" %>
<% rs.MoveNext
Loop
rs.Close
conn.Close
%>
<select size="1" name="ctrlDocsID">
<% Set conn = Server.CreateObject("ADODB.Connection"
conn.Open "DSN=storage"
Select Case selectedDept
Case 0
Set rs = conn.Execute("SELECT * FROM ctrldocs WHERE ctrlDeptID=1"
Case Else
Set rs = conn.Execute("SELECT * FROM ctrldocs WHERE ctrlDeptID=" & selectedDept)
End Select
Do While Not rs.EOF %>
<OPTION VALUE="<%= rs("ctrlDocsID" %>"> <%= rs("doctype" %> - <%= rs("docid" %>
<% rs.MoveNext
Loop
rs.Close
conn.Close %>
</select>
________________
Note that for the first drop down box I have made it submit to itself in the form.
Any help would be appreciated.
First part of code:
There are two dropdown boxes which are linked to each other. That means if I select a value from the first then the second one populates with values accordingly.
Second Part of code
If from the previous page a user enters a barcode ID, the on the next page the two drop down boxes should populate with the correct data.
I am having trouble combining both the codes.
Here they are.
For first Dropdown box: (is accesed through the include command)
<%
Set oTmp = Server.CreateObject("ADODB.Recordset"
oTmp.Open "SELECT * FROM ctrldept", "DSN=storage"
Do While Not oTmp.EOF
Response.Write("<OPTION VALUE=""" & oTmp("ctrlDeptID" & """ "
If Not oRS.EOF And Not oRS.BOF Then
If oRS("ctrlDeptID" = oTmp("ctrlDeptID" Then
Response.Write("SELECTED "
End If
End if
Response.Write(">"
Response.Write(oTmp("department" & " - " & oTmp("deptid" & " "
Response.Write("</OPTION>"
oTmp.MoveNext
Loop
oTmp.Close
Set oTmp = Nothing
%>
For second Dropdown box: (is accesed through the include command)
<%
Set oTmp = Server.CreateObject("ADODB.Recordset"
oTmp.Open "SELECT * FROM ctrlDocs", "DSN=storage"
Do While Not oTmp.EOF
Response.Write("<OPTION VALUE=""" & oTmp("ctrlDocsID" & """ "
If Not oRS.EOF And Not oRS.BOF Then
If oRS("ctrlDocsID" = oTmp("ctrlDocsID" Then
Response.Write("SELECTED "
End If
End if
Response.Write(">"
Response.Write(oTmp("Doctype" & " - " & oTmp("DocID" & " "
Response.Write("</OPTION>"
oTmp.MoveNext
Loop
oTmp.Close
Set oTmp = Nothing
%>
Code for auto populating both the drop down boxes and where the second dropdown box adjusts it self based on the selection of the first drop downbox.
dim selectedDept
If Request("ctrlDeptID" = "" then
selectedDept = "0"
Else
selectedDept = Request("ctrlDeptID"
end if
<% <td width="22%"><select size="1" name="ctrlDeptID" OnChange="frmtypes.submit();">
Set conn = Server.CreateObject("ADODB.Connection"
conn.Open "DSN=storage"
Set rs = conn.Execute("SELECT * FROM ctrldept"
Do While Not rs.EOF %>
<OPTION VALUE="<%= RS("ctrlDeptID" %>" <% If RS("ctrlDeptID" = CInt(selectedDept) Then Response.Write("SELECTED"%>> <%= RS("department" %> - <%= RS("deptid" %>
<% rs.MoveNext
Loop
rs.Close
conn.Close
%>
<select size="1" name="ctrlDocsID">
<% Set conn = Server.CreateObject("ADODB.Connection"
conn.Open "DSN=storage"
Select Case selectedDept
Case 0
Set rs = conn.Execute("SELECT * FROM ctrldocs WHERE ctrlDeptID=1"
Case Else
Set rs = conn.Execute("SELECT * FROM ctrldocs WHERE ctrlDeptID=" & selectedDept)
End Select
Do While Not rs.EOF %>
<OPTION VALUE="<%= rs("ctrlDocsID" %>"> <%= rs("doctype" %> - <%= rs("docid" %>
<% rs.MoveNext
Loop
rs.Close
conn.Close %>
</select>
________________
Note that for the first drop down box I have made it submit to itself in the form.
Any help would be appreciated.