Implement level two Drop-down list with ASP program

Source: Internet
Author: User
Tags array implement
Program | dropdown | drop-down list has [group] and [user] Two data tables, requires that the data be read from both tables and displayed as a level two Drop-down table, and the options in the [user] list change accordingly when you select an option in the [Group] list.
The [Group] table corresponds to a dataset of Rsgroup, with the following fields: Lngid_group, Strname_group
The [user] table corresponds to a dataset of Rsuser, with the following fields: Lngid_user, Lnggroupid, Strname_user
Idea: Create a drop-down list of group and user, read the data for Rsgroup and Rsuser, and then create the Change_select () function to update the user Drop-down list when the group's Drop-down list is changed.

The code is as follows:
<!-group Drop-down List-------------->
<select name= "Sltgroupid"
>
<option value= "0" > User group ......</option>
<%
For i = 1 to Rsgroup.recordcount
Response.Write "<option value= '" & Lngid_group & "' >" & strname_group & "</option>"
Rsgroup.movenext
Next
%>
</select>
<!-user Drop-down List-------------->
<select name= "Sltuserid" >
<option value= "0" > User ......</option>
</select>
<script language = "JavaScript" >
Read the Rsuser data
Arrselect=new Array ();
Arrselect[0] = new Array ("User ...", 0,0)
<%
For i = 1 to Rsuser.recordcount
%>
arrselect[<%= I%>]=new Array ("<%= strname_user%>", "<%= lnggroupid%>", "<%= lngID_User%>");
<%
Rsuser.movenext
Next
%>
function to update the user Drop-down list
function Change_select (selvalue)
{
document.all.sltuserid.length=0;
var i;
for (i=0;i<arrselect.length;i++)
{
if (Arrselect[i][1]==selvalue)
{
var newoption=new Option (arrselect[i][0],arrselect[i][2]);
Document.all.sltUserID.add (newoption);
}
}
}
</script>

The results of the operation are as follows:
<!-group Drop-down List-------------->
<select name= "Sltgroupid"
>
<option selected value= "0" > User group ......</option>
<option value= ' 1 ' > Immediate institutions </option>
<option value= ' 2 ' > Office </option>
<option value= ' 3 ' > Technical Department </option>
</select>
<!-user Drop-down List-------------->
<select name= "Sltuserid" >
<option selected value= "0" > User ......</option>
</select>
<script language = "JavaScript" >
Read the Rsuser data
Arrselect=new Array ();
Arrselect[0]=new Array ("User ...", 0,0)
Arrselect[1]=new Array ("General manager", "1", "1");
Arrselect[2]=new Array ("Network Center", "1", "15");
Arrselect[3]=new Array ("Public Platform", "1", "4");
Arrselect[4]=new Array ("aftermarket department", "1", "20");
Arrselect[5]=new Array ("Guangzhou", "2", "24");
Arrselect[6]=new Array ("Shanghai", "2", "23");
Arrselect[7]=new Array ("Pre-sales Support", "3", "8");
Arrselect[8]=new Array ("Research and Development Center", "3", "9");
function to update the user Drop-down list
function Change_select (selvalue)
{
Ditto, slightly.
}
</script>

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.