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

3 level drop down menu

Status
Not open for further replies.

emozley

Technical User
Jan 14, 2003
769
GB
Hi,

I have a form which has various text fields that can be filled in. I also have three drop down menus which are all linked. Department, Category and Subcategory. The idea is that if you choose a certain department you can only see certain categories and if you choose certain categories you can only see certain subcategories.

Originally I tried to do it by building a recordset then using javascript to do the rest but I didn't really know what I was doing so gave up on that approach.

The way I have gone now is to use onClick="submit()" so that when you select an option it posts to the same page then builds the other menus accordingly so for example to build the categories menu we look at what the department has been set to (DocsDeptMenu)

<%
TBL.Open "SELECT DocsCatID, DocsCat FROM DocsCat WHERE DocsCat.DocsDept=" & DocsDeptMenu, DB
%>
<select name="DocsCat" onClick="submit()">
<option value="0">Select Category</option>
<%
Do While Not TBL.EOF
%>
<option <%
If INT(Request.Form("DocsCat"))=TBL("DocsCatID") Then
Response.Write("SELECTED")
CatOption=TRUE
End If
%> value="<% = TBL("DocsCatID") %>"><% = TBL("DocsCat") %></option>
<%
TBL.MoveNext
Loop
TBL.Close
%>
</select>

This works fine to an extent but because this is a form in its own right I have to put it at the start of the page as I can't have a <form></form> within a form whereas ideally I would like the form layout to be different with the document title and the author first then the user selects the department, category etc.

Is there any way round this using my approach or will I have to do it all client side?

cheers

Ed

 
I have seen some prety slick client-side menus with CSS.
 
Is there any way you can move the other form's open form tag lower in the page? If you just want a few things before your triple dropdodown, I would think that the second form could easily start where the menu ends, unless you need those values in the second form, that is :)

Another option would be to use the same form tags but to use some logic to show your server-side process that it was a dropdown submit and not a button/form submit. Basically you could make an onChange event that both submitted the form and made a difference that the server would appreciate, something like:
Code:
<select name="selDepartment" onChange="myForm.action='mypagename.asp?select=cat';myForm.submit();">

and

<select name="selCategory" onChange="myForm.action='mypagename.asp?select=subcat';myForm.submit();">
Now when your page loads you can check if the querystring has a value for the word "select". If it does then it was a postback for your dropdown, if it doesn't then it was either a first load or your regular submit routine. This works just as well if your form actually points to a second page becuse then your cases are first load or postback.

In your ASP all you would then need to do is add some if statements:
Code:
'1) do your SQL/loop to do the dept dropdown

'2) check for category
If Request.QueryString("select") = "cat" Then
   '3) do your SQL/loop for categories
End If

'4) check for subcat request
If equest.QueryString("select") = "subcat" Then
   '5) do your subcat SQL/loop for subcat's
End If

If your posting your whole form back to this page, then in your code to check if this was a form submission you could add in a simple check to see if Request.QueryString("select") is empty:
Code:
'some logic to handle the form
If Request.QueryString("select") = "" And Request.Form("someField") <> "" Then
   'process the form values
End If

If your code doesn't process the form post in the same page then you don't need to worry about it.


Hope this helps,
-T
[/code]

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top