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

Linked List Boxes

Status
Not open for further replies.

Sunil606

Programmer
Dec 8, 2003
27
GB
Hi,
I am trying to create a linked list box where a user selects a room number from a list box and on selection of the room number another list boxes opens up beneath it contain a list of the serial numbers in that particular room chosen by the user. If anyone has any ideas or could point me in the right direction I would appreciate it. I have looked at the FAQs and tried them with no success; can some please help or point me in the right direction please.


<!--#include file=&quot;connectionstring.asp&quot; --> <!--'Server side include used to hold the database connection details. Page 481 in Beginning ASP 3.0 book-->

<!-- METADATA TYPE=&quot;typelib&quot; 'This makes the ADO constants available without having to define them as constants. This information has been taken from page 519 of Beginning ASP 3.0
FILE=&quot;C:\Program Files\Common Files\System\ado\msado15.dll&quot; -->

<%
Dim strConnect
Dim objRS ' Declare variable for recordset object
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;) 'Create the the recordset object
objRS.open &quot;Room&quot;, strConnect
objRS.MoveFirst

%>
<HTML>
<HEAD>


<TITLE>MHCHS - Report a fault</TITLE>
</HEAD>
<BODY BGCOLOR=&quot;#FFFF80&quot;>







<P ALIGN=&quot;CENTER&quot;><U><B>Welcome to the Online Fault Management System</B></U></P>
<P ALIGN=&quot;CENTER&quot;><B><B>You are logged in as a <% =session(&quot;Role&quot;) %> </B></U> </P>





<%

If Session(&quot;Role&quot;) = &quot;Technician&quot; Then
Response.write &quot;<A HREF=FaultDetails.asp>Fault Reports</A><BR>&quot;
Response.write &quot;<A HREF=AssignedJobs.asp>View jobs assigned</A><BR>&quot;
Response.write &quot;<A HREF=home.asp>Log out</A><BR>&quot;
Response.write &quot;<A HREF=ChangePassword.asp>Change Password</A><BR>&quot;


ElseIF session(&quot;Role&quot;) = &quot;User&quot; Then
'Response.write &quot;<A HREF=ReportFault.asp>Report a fault</A><BR>&quot;
Response.write &quot;<A HREF=ViewFaultProgress.asp>View fault progress reports</A><BR>&quot;
Response.write &quot;<A HREF=home.asp>Log out</A><BR>&quot;
Response.write &quot;<A HREF=ChangePassword.asp>Change Password</A><BR>&quot;

Else
Response.write &quot;<A HREF=AssignJobs.asp>Assign a job</A><BR>&quot;
Response.write &quot;<A HREF=ViewDailyLog.asp>View daily fault log</A><BR>&quot;
Response.write &quot;<A HREF=Weighting.asp>View Technician weighting</A><BR>&quot;
Response.write &quot;<A HREF=ViewProgressDetails.asp>View Progress details</A><BR>&quot;
Response.write &quot;<A HREF=Register.asp>Create User Account</A><BR>&quot;
Response.write &quot;<A HREF=ChangePassword.asp>Change Password</A><BR>&quot;
Response.write &quot;<A HREF=home.asp>Log out</A><BR>&quot;
End If
%>



<FORM ACTION = &quot;AddFault.asp&quot; METHOD = &quot;POST&quot;>



<P ALIGN=&quot;CENTER&quot;><b>Fault Reported by :<% =session(&quot;StaffName&quot;) %></B><BR></B>
<P ALIGN=&quot;CENTER&quot;><b>Email Address:<% =session(&quot;EmailAddress&quot;) %></B><BR></B>
<P ALIGN=&quot;CENTER&quot;><b>Type Of Fault </b><SELECT NAME =&quot;FaultType&quot; Size=&quot;1&quot;>
<OPTION SELECTED VALUE=&quot;Hardware&quot;>Hardware</OPTION>
<OPTION VALUE=&quot;Software&quot;>Software</OPTION>
<OPTION VALUE=&quot;Network&quot;>Network</OPTION>
<OPTION VALUE=&quot;Other&quot;>Other</OPTION>

'Code used and adapted from Beginning ASP Databases on page 162


</SELECT><p align=&quot;CENTER&quot;><b>Location </b>
<SELECT NAME=&quot;Location&quot; SIZE=&quot;1&quot;>

<%
Do While NOt objRS.EOF
Response.Write &quot;<OPTION VALUE='&quot; & objRS(&quot;RoomNo&quot;) & &quot;'>&quot; & &quot;<BR>&quot;
Response.Write objRS(&quot;RoomNo&quot;) & &quot;</OPTION>&quot; & &quot;<BR>&quot;
objRS.MoveNext
Loop
objRS.Close
Set objRS = Nothing
%>
</SELECT></B><BR>










<P ALIGN=&quot;CENTER&quot;><TextArea Name = &quot;Details&quot; COLS=50 ROWS= 10></TextArea><BR><BR>





<input type = &quot;Submit&quot; Value = &quot;Submit Fault&quot;></a><input type = &quot;Reset&quot; Value = &quot;Clear Form&quot;><BR>
<BR>







</P>
</FORM>









<P ALIGN=&quot;CENTER&quot;> </P>












</B>
</FORM>












</BODY>
</HTML>

Thanks in advance.
 
Hi Sunil,

Try this one. The javascript is just a small one that causes the browser to jump to the URL inside the Value of the option in the select box.

Notice the variable &quot;prdt&quot;. The value of &quot;prdt&quot; comes from the QueryString and is the index value of the Product in this example. The second select box (Sub-Product) will only come up if and only if &quot;prdt&quot; has a value, which it can only get if somebody selects a Product.

1) User selects a product. The browser jumps to faqdatalist.asp?prdt=(index value of the product) which is the same page but with a bit of extra data in the url.
2) If...Then statement which controls the second select box. It sees that prdt equals something and allows the code for the Sub-Product to run.
3) The Product box will ramain on the product that was selected and the user can then select the Sub-Product.

The Sub-Product table is designed as follows...

SPID = Sub-Product ID
SubProduct = Name of the Sub-Product
SubProductOf = This field has a relationship to the Product table. The data in this field is the Product ID the Sub-Product belongs to.

I use this code to make changes to a SQL statement. You can see a working example at
Code:
<script type=&quot;text/javascript&quot; language=&quot;JavaScript&quot;>
	<!--
	function jump(fe){
		var opt_key = fe.selectedIndex;
		var url_val = fe.options[opt_key].value;
		window.open(url_val,'_top');
		return true;
 	}
 	//-->
</script>
<table><tr><td>Product: 
<%
x_PIDList = &quot;<select name='x_PID' onchange='jump(this)'><option value='faqdatalist.asp?cmd=reset&prdt='>All Products</option>&quot;
sqlwrk = &quot;SELECT [PID], [Product] FROM [Product]&quot; & &quot; ORDER BY [Product] Asc&quot;
Set rswrk = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rswrk.Open sqlwrk, conn, 1, 2
If Not rswrk.Eof Then
    datawrk = rswrk.GetRows
    rowswrk = UBound(datawrk, 2)
    x_PID = prdt
    For rowcntwrk = 0 To rowswrk
        x_PIDList = x_PIDList & &quot;<option value='faqdatalist.asp?cmd=reset&prdt=&quot; & datawrk(0, rowcntwrk) & &quot;'&quot;
        If CStr(&quot;&quot; & datawrk(0, rowcntwrk)&&quot;&quot;) = CStr(&quot;&quot; & x_PID & &quot;&quot;) Then
            x_PIDList = x_PIDList & &quot; selected&quot;
        End If
        x_PIDList = x_PIDList & &quot;>&quot; & datawrk(1, rowcntwrk) & &quot;</option>&quot;
    Next
End If
rswrk.Close
Set rswrk = Nothing
x_PIDList = x_PIDList & &quot;</select>&quot;
Response.Write x_PIDList
%>
</td>
<%
prdt = Request.Querystring(&quot;prdt&quot;)
If prdt <> &quot;&quot; Then
%>
<td><font size=&quot;-1&quot;>Sub-Product: </font></td>
<td>
<%


x_SPIDList = &quot;<select name='x_SPID' onchange='jump(this)'><option value='faqdatalist.asp?cmd=reset&prdt=&quot; & prdt & &quot;&subprdt='>All &quot; & x_subprdttextpl & &quot;</option>&quot;

sqlwrk = &quot;SELECT [SPID], [SubProduct] FROM [SubProduct]&quot;
If prdt <> &quot;&quot; Then
	sqlwrk = sqlwrk & &quot; WHERE [SubProductOf] = &quot; & prdt & &quot; ORDER BY [SubProduct] Asc&quot;
Else
	sqlwrk = sqlwrk & &quot; ORDER BY [SubProduct] Asc&quot;
End If
Set rswrk = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rswrk.Open sqlwrk, conn, 1, 2

If Not rswrk.Eof Then
    datawrk = rswrk.GetRows
    rowswrk = UBound(datawrk, 2)
    'x_SPID = subprdt
    'x_PID = prdt

    For rowcntwrk = 0 To rowswrk
        x_SPIDList = x_SPIDList & &quot;<option value='faqdatalist.asp?cmd=reset&prdt=&quot; & prdt &&quot;&subprdt=&quot; & datawrk(0, rowcntwrk) & &quot;'&quot;
        If CStr(&quot;&quot; & datawrk(0, rowcntwrk)&&quot;&quot;) = CStr(&quot;&quot; & subprdt & &quot;&quot;) Then
            x_SPIDList = x_SPIDList & &quot; selected&quot;
        End If
        x_SPIDList = x_SPIDList & &quot;>&quot; & datawrk(1, rowcntwrk) & &quot;</option>&quot;
    Next

End If
rswrk.Close
Set rswrk = Nothing
x_SPIDList = x_SPIDList & &quot;</select>&quot;
Response.Write x_SPIDList
%>

</td></tr></table>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top