Dynamic | data | Database here is the province and the city as an example, as the use of the database, please first set up a database Dlist.mdb
Database name: Dlist.mdb
Province Table name: Province
Fields are: p_id (type: AutoNumber), P_name (type: text, province name)
City Table Name:
Fields are: c_id (type: AutoNumber), C_pid (type: text, province name, equal to P_name in province table), C_name (type: text, city name)
The source program is as follows, save as ASP file can be executed.
------------------------------------------------------------
<%
Dim id
Id=request. QueryString ("id")
If id= "1" Then
Response. Write "<br>" & Request. Form ("Lstb")
Response. Write "<br>" & Request. Form ("LSTs")
End If
%>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<TITLE>JS Dynamic column representation case </title>
<script language= "JavaScript" >
<!--
var ssort = new Array ();
var num = 0;
<%
Dim conn,rs,grs,i,j,pstr
Pstr= ""
Set Conn=server.createobject ("Adodb.connection")
Set Rs=server.createobject ("Adodb.recordset")
Set Grs=server.createobject ("Adodb.recordset")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ("Dlist.mdb")
' Write Province JS array
Rs.Open "select * from Province;", conn,1,1
For I=0 to Rs.recordcount-1
Pstr=pstr & "<option value=" "" & RS ("P_name") & "" > "& RS (" P_name ") &" </option> "
Getsub (RS ("P_name"))
Rs.movenext
Next
Rs.close ()
Set rs=nothing
Set grs=nothing
' The process of writing the City JS array according to the province
Sub Getsub (pname)
Grs.open "SELECT * from city where c_pid= '" & PName & "';", conn,1,1
For J=1 to Grs.recordcount
Response.Write "ssort[num++] = new Array (" "" & Grs ("C_name") & "" "," "" & PName & "" "", "" & VbCrlf
Grs.movenext
Next
Grs.close ()
End Sub
%>
var nssortcount = num;
function Sdbsortchange (Cmbsdbsort, Cmbssort)
{
var nselsdbsort = Cmbsdbsort.selectedindex;
var ssdbsort = Cmbsdbsort.options[nselsdbsort].value;
cmbssort.length = 0;
Cmbssort.options[0] = new Option ('-Please select-', ');
for (var i=0; i<nssortcount; i++)
{
if (ssort[i][1] = = Ssdbsort)
{
Cmbssort.options[cmbssort.length] = new Option (ssort[i][0], ssort[i][0]);
}
}
}
function Initssort (Cmbsdbsort, Cmbssort)
{
var nselsdbsort = Cmbsdbsort.selectedindex;
var ssdbsort = Cmbsdbsort.options[nselsdbsort].value;
var sssort = Cmbssort.options[0].value;
cmbssort.length = 0;
Cmbssort.options[0] = new Option ('-Please select-', ');
var n = 0;
for (var i=0; inssortcount; i++)
{
if (ssort[i][1] = = Ssdbsort)
{
Cmbssort.options[cmbssort.length] = new Option (ssort[i][0], ssort[i][0]);
if (ssort[i][0] = = Sssort)
Cmbssort.options[cmbssort.length-1].selected = true;
}
}
}
-->
</script>
<body>
<p> </p>
<p> </p>
<p> </p>
<form action= "index.asp?id=1" method= "post" name= "Frmdlist" id= "Frmdlist" >
<table width= "408" border= "0" align= "center" cellpadding= "2" cellspacing= "2" >
<tr>
<TD width= align= "center" >js Dynamic list Example </td>
</tr>
<tr>
<TD align= "center" ><%response.write "<select name=" "Lstb" "style=" "width:200" "onchange=" "SdbSortChange" (this,frmdlist.lsts); "" > "& pstr &" </select> "%>
</td>
</tr>
<tr>
<TD align= "center" > </td>
</tr>
<tr>
<TD align= "center" ><select style= "width:200" name= "LSTs" id= "LSTs" >
</select>
</td>
</tr>
</table>
<p align= "center" >
</p>
<p align= "center" > </p>