Create a linkage menu using ASP

Source: Internet
Author: User

<%
Response. write "<select name =" "class_id" "onChange =" "classselect (this);" ">" & vbCrlf
StrJS = "function classselect (obj) {for (var I = document. refer. class_c_id.options.length; I> = 0; I --) {document. refer. class_c_id.options [I] = null; "& vbCrlf 'clears the JS code of the original option object
SQL = "select class_id, class_name from class order by class_order"
Set rsw.conn.exe cute (SQL)
While not rs. eof
Response. write "<option value =" & rs ("class_id ")
If class_id <> "then
If rs ("class_id") = CInt (class_id) then' enables the option of the corresponding parent class to be selected. The CInt function must be added; otherwise, the function will not work.
Response. write "selected"
End if
End if
Response. write ">" & rs ("class_name") & "</option>" & vbCrlf
StrJS = strJS & "}" & vbCrlf & "if (obj. options [obj. selectedIndex]. value =" & rs ("class_id") & ") {" & vbCrlf

Sql1 = "select class_c_id, class_c_name from class_c where class_id =" & rs ("class_id") & "order by class_c_order"
Set rs1=conn.exe cute (sql1)
                  
While not rs1.eof
StrJS = strJS & "document. refer. class_c_id.options [document. refer. class_c_id.options.length] = new Option ('"& rs1 (" class_c_name ") &"', '"& rs1 (" class_c_id ") &"'); "& vbCrlf
Rs1.movenext
Wend

Rs. movenext
Wend
                  
'To make the option of the first subclass not null ============================== ======================================
If class_id = "" then
SQL = "select class_id, class_name from class"
Set rsw.conn.exe cute (SQL)
SQL = "select class_c_id, class_c_name from class_c where class_id =" & rs ("class_id") & "order by class_c_order"
Else
SQL = "select class_c_id, class_c_name from class_c where class_id =" & class_id & "order by class_c_order"
End if
Set rsw.conn.exe cute (SQL)
While not rs. eof
If class_c_id <> "then
If rs ("class_c_id") = CInt (class_c_id) then' makes the option of the corresponding subclass selected. If placed before string connection
StrJS3 = "var option_length = document. refer. class_c_id.options.length;" & vbCrlf
StrJS2 = "document. refer. class_c_id.options [option_length]. selected = true;" & vbCrlf
Else
StrJS3 = ""
End if
End if
StrJS1 = strJS1 & strJS3 & "document. refer. class_c_id.options [document. refer. class_c_id.options.length] = new Option ('"& rs (" class_c_name ") &"', '"& rs (" class_c_id ") &"'); "& vbCrlf
Rs. movenext
Wend
'================================================ ========================================================== ===
                  
StrJS = strJS & "}" & vbCrlf & "}" & vbCrlf
Response. write "</select>"
Response. write "<select name =" "class_c_id" ">"
Response. write "</select>"
Response. write "<script language =" "JavaScript" ">" & vbCrlf 'output JS scripts
Response. write strJS1 & vbCrlf & strJS2 & vbCrlf
Response. write strJS & "</SCRIPT>" & vbCrlf
Conn. close
Set conn = nothing
%>

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.