Problem:
Table
Code name
Company 1, 0001
Company 2, 0002
Table B
Maincode subcode subname
0001 1001 department 1
0001 1002 Department 2
0002 2001 Department 3
0002 2002 Department 4
Two select statements. If Company 1 is selected as the first select statement, department 1 and Department 2 are the same as the primary code.
Similarly, for many registered websites, if one select is "Shandong", the other is all cities in Shandong. If you select "Shanxi ". The other dynamic is all cities in Shanxi.
Solution 1:
<Script language = "JavaScript">
VaR onecount;
Onecount = 0;
Subcat = new array ();
<%
Int COUNT = 0;
Java. SQL. resultset RS1 = dbmanage.exe cutequery ("select hydm, zhydm, zhymc from Zhy"); // read data
While (rs1.next ())
{
String selhydm = rs1.getstring ("hydm"). Trim ();
String zhydm = rs1.getstring ("zhydm"). Trim ();
String zhymc = rs1.getstring ("zhymc"). Trim ();
%>
Subcat [<% = count %>] = new array ("<% = zhydm %>", "<% = selhydm %> ", "<% = zhymc %>"); // generates an array
<%
Count = count + 1;
}
If (RS1! = NULL) dbmanage. closeconn ();
%>
Onecount = <% = count %>;
Function changelocation (ID)
{
Document. form1.selzhy. Length = 0;
VaR hydm = ID;
VaR I;
Document. form1.selzhy. Options [0] = New Option ('select sub-industry category ','');
For (I = 0; I <onecount; I ++)
{
If (subcat [I] [1] = hydm)
{
Document. form1.selzhy. Options [document. form1.selzhy. Length] = New Option (subcat [I] [2], subcat [I] [0]);
}
}
}
</SCRIPT>
<Table width = "500" border = "0" cellspacing = "0" cellpadding = "0" align = "center">
<Tr>
<TD width = "180" Height = "20" align = "right"> select industry category: </TD>
& Lt; TD width = "320" & gt;
<Select name = "selhy" onchange = "changelocation (document. form1.selhy. Options [document. form1.selhy. selectedindex]. Value)" size = "1">
<Option value = "2"> select industry type </option>
<%
Rs = dbmanage.exe cutequery ("select * from hy ");
While (Rs. Next ())
{
String hydm = Rs. getstring ("hydm"). Trim ();
String hymc = Rs. getstring ("hymc"). Trim ();
%>
<Option value = "<% = hydm %>"> <% = hymc %> </option>
<%
}
If (RS! = NULL) dbmanage. closeconn ();
%>
</SELECT>
</TD>
</Tr>
<Tr>
<TD Height = "20" align = "right"> select a sub-industry category: </TD>
<TD>
<Select name = "selzhy">
<Option value = "" selected> select a sub-industry Category </option>
</SELECT>
</TD>
</Tr>
</Table>
Solution 2:
<Form name = form1>
<Select name = province onchange = "cityname (this. selectedindex)">
<Option value = ""> select a province name </option>
</SELECT>
<Select name = city>
<Option value = ""> select a city name </option>
</SELECT>
</Form>
<Script language = JavaScript>
VaR city1 = ["Hangzhou", "Ningbo", "WenZhou", "Shaoxing", "Jinhua", "Huzhou"];
VaR city2 = ["Nanjing", "Suzhou", "Wuxi", "Changzhou", "Zhenjiang", "Xuzhou"];
VaR city3 = ["Hefei", "PiXian", "Huangshan", "Qimen", "Xiuning"];
VaR city4 = ["Nanchang", "Jiujiang", "Ganzhou", "Shangrao", "Xinyu", "Jingdezhen"];
VaR provincename = ["Zhejiang", "Jiangsu", "Anhui", "Jiangxi"];
Function province ()
{
VaR E = Document. form1.province;
For (VAR I = 0; I <provincename. length; I ++)
E. Options. Add (New Option (provincename [I], provincename [I]);
}
Function cityname (N)
{
VaR E = Document. form1.city;
For (VAR I = E. Options. length; I> 0; I --) E. Remove (I );
If (n = 0) return;
VaR A = eval ("city" + n); // obtain the array name of the city.
For (VAR I = 0; I <A. length; I ++) E. Options. Add (New Option (a [I], a [I]);
}
Function window. onload ()
{
Province (); // grant content to the province name drop-down menu at the beginning
}
</SCRIPT>
Summary:
Static implementation, you can use JavaScript cascade select. Here is a good encapsulation class and example: Explain
For dynamic implementation, you can use XML to go To the backend for dynamic values. You can also find corresponding examples on the Internet;
The latter mainly aims to solve the problem of slow load time when the data volume is large. Based on the current requirements, the former should be able to meet the requirements.