Implementation of level 2 drop-down list

Source: Internet
Author: User

Implementation of level 2 drop-down list

There are two data tables: [group] and [user]. You must read the data from these two tables and perform the data as a two-level drop-down table. When you select the option in the [group] list, the options in the [user] list are changed accordingly.

The data set corresponding to the [group] Table is rsGroup and has the following fields: lngID_Group and strName_Group.
[User] The table's dataset is rsUser, which has the following fields: lngID_User, lngGroupID, strName_User

Idea: first create a drop-down list of group and user; read data of rsGroup and rsUser respectively; then create the change_select () function. When the drop-down list of group is changed, execute this function to update the user drop-down list.

The Code is as follows:
<! -Group drop-down list ------------>
<Select name = "sltGroupID"
OnChange = "javascript: change_select (this. options [this. selectedIndex]. value)">
<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 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
%>

// Update the user drop-down list Function
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 running result is as follows:
<! -Group drop-down list ------------>
<Select name = "sltGroupID"
OnChange = "change_select (this. options [this. selectedIndex]. value)">
<Option selected value = "0"> User Group ...... </Option>
<Option value = '1'> affiliated institution </option>
<Option value = '2'> Office </option>
<Option value = '3'> Technology Department </option>
</Select>

<! -User drop-down list ------------>
<Select name = "sltUserID">
<Option selected value = "0"> User ...... </Option>
</Select>

<Script language = "JavaScript">
// Read 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 ("aftersales Department", "1", "20 ");
ArrSelect [5] = new Array ("Guangzhou", "2", "24 ");
ArrSelect [6] = new Array ("Shanghai", "2", "23 ");
ArrSelect [7] = new Array ("pre-sale support", "3", "8 ");
ArrSelect [8] = new Array ("R & D center", "3", "9 ");

// Update the user drop-down list Function
Function change_select (selvalue)
{
// Same as above, omitted.
}
</Script>
 

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.