dreamweaver+asp make dynamic Level two menu

Source: Internet
Author: User
Tags table name dreamweaver
dreamweaver| Menu | dynamic | Level two menu

In general, this situation is to the two level of the directory useful, for now the site has been circulating a lot of JS, but there are no outside of those who make like me such a rookie dizzy JS code. Suddenly for ... All of a sudden array of.

First you have to build a table, of course, if you have already built a table of contents, then this step can be omitted. But one thing to be reminded: This table is the basis of my example (I don't know if that's right).

Since I used the table is access, so the table is not said, listing only the corresponding field name of the two tables (database name: Db.mdb):

Table Name: type_tree--Parent class
Fields: type_id (AutoNumber) type_name (category name)

Table Name: s_type--Subclass
Fields: ID (AutoNumber) s_name (subcategory name) type_id (parent class ID)--corresponds to the parent class table

The database connection is now established:

Dim Conn, connstr

Set conn = server. CreateObject ("ADODB.") Connection ") ConnStr =" Provider = microsoft.jet.oledb.4.0; " ConnStr = connstr & "Data Source =" & Server.MapPath ("Db.mdb") Conn.Open ConnStr

The above code should not be explained, it is commonly used code.

Now into the substantive operation:)

The two-level association menu is generally the following pull menu to do, here I am no exception, the same with the Drop-down menu to do.
It's just that there's a different place.

is a jump menu, this is very important, the success of the whole look at the menu is not used right! Here is the code for the Jump Menu!

<select name= "a" >
<%
sql = "SELECT [Type_id],[type_name] from [Type_tree]"
Set rs = conn.execute (sql) ' Gets the ID and name of the parent class
If rs.eof or Rs.bof then
Response.Write "<option>-----</option>" ' If there is no record, show-----
Else
While not (rs.eof or RS.BOF) ' has records, the parent name is listed to form a drop-down.
Response.Write ("<option value= '? sec=" & RS (0) & "")
If CStr (RS (0)) = Request.QueryString ("SEC") then
Response.Write "Selected"
End If
Response.Write (">" & RS (1) & "</option>")
Rs.movenext
Wend
Rs.movefirst ' moves the cursor to the first bar for the following.
End If
%>
</select>

Oh, yes, there is a piece of code forgot to post, this is the key to jump the sound of vegetables ah, see my careless! To fill up on:

<script language= "javascript" type= "Text/javascript" >
<!--
function Mm_jumpmenu (targ,selobj,restore) {//v3.0
Eval (targ+ "location=" "+selobj.options[selobj.selectedindex].value+");
if (restore) selobj.selectedindex=0;
}
-->
</script>

The above code posted to

Here's the code for the menu, because the loop is a little more complicated than the judgment, and you guys need to see it clearly.

<select name= "Second"
<%if rs.eof or Rs.bof then
Response.Write ("<option>--------</ Option> ")
Else
If Request.QueryString (" sec ") =" then   "Get sec value after jump
   temp=rs (0)    if empty, set the value of temp to the value of the first record
Else
   temp = Request.QueryString ("SEC")    ' otherwise the value received
End If
subsql = "SELECT [S_name] from [S_type] where type_id= '" &temp& ' "
Set Subrs = Conn.execute (subsq L)    ' list all records for temp
if subrs.eof or Subrs.bof then
  Response.Write ("<option>-----</ Option> ")
  If there are no records, show-----
Else
 while not (subrs.eof or SUBRS.BOF) in this list Otherwise, you use a loop to list all the records that match the criteria.
   Response.Write ("<option value=" & Subrs (0) & ">" & Subrs (0) & "</option>") Br> subrs.movenext
 wend
End If
End if

' Close all recordsets
Subrs.close
Set Subrs = Nothing
Rs.close
Set rs = Nothing
Conn.close
Set conn = Nothing
%>
</select>

So far, the two-level menu has been completed, a very simple look at me to say. People can not understand it, anyway, I do not know what to say. Experts are generous to enlighten ah.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.