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

Dropdown dynamicly build a table 1

Status
Not open for further replies.

Lavey

IS-IT--Management
Jun 1, 2001
115
DE
Hi,

I'm super new to ASP so pardon my stoopidness.. anyway i've had a read thru the faqs on dynamic dropdowns and they mostly relate to filling second dynamic dropdowns.

What i want to do is build a page that takes a creates a dynamic dropdown that when a user selects an option it generates a stocklist based on the 'type'. I have been going round in circles with is one and not sure where to go now...

my code that works for the dropdown is this:

Code:
<!-- #include file = "Datastore.asp" -->
<%
sub buildDropDown()
Dim strConnect, objRS

	Set objRS = Server.CreateObject ("ADODB.Recordset")
	objRS.Open "qryDropDown", conn

	Response.Write "<form name='typeSelect'>"
	Response.Write "<select name='dropdownlist'>" & vbCrLf
	Response.Write "<option selected='selected' value=''>Choose....</option>"

	While objRS.EOF = false
		Response.Write "<option value=" & objRS.fields("Type").value & ">" & objRS.Fields("Type").Value & "</option>" & vbCrLf
		objRS.movenext
	Wend
	Response.Write "</select></form>" & vbCrLf
end sub
%>

<html>
<head>
<title>Database List</title>
</head>
<body>

<%
call buildDropDown()
%>

</body>
</html>

i thought that maybe something on the onChange event would work, but i guess javascript cant call/pass this to my vbscript..

Code:
<%
sub selectMe(strIn)
Dim strCriteria, objRS

strCriteria = "Type = '" & strIn & "'"

	Set objRS = Server.CreateObject ("ADODB.Recordset")
	objRS.Open "qryStock", conn
	objRS.Filter = strCriteria
	
	Response.Write "<TABLE width='50%' border='0'><TR>" 
		While NOT objRS.EOF
			Response.Write "<TD>" & objRS("SubType") & "</TD>" & "<TD>" & objRS("Desc") & "</TD> </TR>" 
			objRS.MoveNext
		Wend
	Response.Write "</TABLE></table>"
	objRS.Close
	Set objRS = Nothing
end sub
%>

<%
sub buildDropDown()
Dim strConnect, objRS

	Set objRS = Server.CreateObject ("ADODB.Recordset")
	objRS.Open "qryDropDown", conn

	Response.Write "<form name='typeSelect'>"
	Response.Write "<select name='dropdownlist' onchange='selectMe(this)'>" & vbCrLf
	Response.Write "<option selected='selected' value=''>Choose....</option>"
	While objRS.EOF = false
		Response.Write "<option value=" & objRS.fields("Type").value & ">" & objRS.Fields("Type").Value & "</option>" & vbCrLf
		objRS.movenext
	Wend
	Response.Write "</select></form>" & vbCrLf
end sub
%>

:S stuck :(

____________________________________
Eat [pc3], Sleep [pc3], Live [pc3]
 
Since ASP runs at the server and Javascript runs on the client, you have an issue with what you are trying to accomplish. Do you want the page to do a trip back to the server to get the sublist that you want to build? That would be the easiest to accomplish. Just pass the selected value through submitting the form (you can have the form submit as an onChange event in the dropdown) and have the asp page get the values of the sublist, build the table, and return it to the user.

If you want to accomplish this without a round trip to the server, you will need to pass all the sublist items theat correspond to each item in the dropdown on the first page. Javasript could then write out the list based on the selected item.
 
thank you for your clarification, wasn't sure on the <% %> and <script> implications (server/client).
I used the first option (with some help from other posts in this forum :D) and works sweet.

Code:
<!-- #include file = "Datastore.asp" -->

<script language="javascript">
function SubmitIt()
	{
	window.location.href = 'Listing.asp?fcmb=' + document.typeSelect.dropdownlist.value;
    }
</script>

<%
sub selectMe()
Dim strCriteria, objRS

strCriteria = request.querystring("fcmb")
response.write strCriteria

	Set objRS = Server.CreateObject ("ADODB.Recordset")
	strSQL = "SELECT tblStock.Type, tblStock.SubType, tblStock.Desc, tblStock.Price FROM tblStock WHERE (((tblStock.Type)='" & strCriteria & "'));"

	objRS.Open strSQL, conn


	Response.Write "<TABLE width='50%' border='0'><TR>" 
		While NOT objRS.EOF
			Response.Write "<TD>" & objRS("SubType") & "</TD>" & "<TD>" & objRS("Desc") & "</TD> </TR>" 
			objRS.MoveNext
		Wend
	Response.Write "</TABLE></table>"
	objRS.Close
	Set objRS = Nothing
end sub
%>

<%
sub buildDropDown()
Dim strConnect, objRS

	Set objRS = Server.CreateObject ("ADODB.Recordset")
	objRS.Open "qryDropDown", conn

	Response.Write "<form name='typeSelect'>"
	Response.Write "<select name='dropdownlist' onChange=(SubmitIt())>" & vbCrLf
	Response.Write "<option selected='selected' value=''>Choose....</option>"
	While objRS.EOF = false
		Response.Write "<option value=" & objRS.fields("Type").value & ">" & objRS.Fields("Type").Value & "</option>" & vbCrLf
		objRS.movenext
	Wend
	Response.Write "</select></form>" & vbCrLf
end sub
%>

<html>
<head>
<title>Database List</title>
</head>
<body>

<%
if request.querystring("fcmb") = "" then 
	call buildDropDown()
else
	call buildDropDown()
	call selectMe()
end if
%>

</body>
</html>

Again, thaks for the prompt.. appreciate the member support here as always :)

____________________________________
Eat [pc3], Sleep [pc3], Live [pc3]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top