Read the dynamic list of records from the database (no initial values)

Source: Internet
Author: User
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 ">
&LT;TITLE&GT;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>
&LT;TD width= align= "center" >js Dynamic list Example </td>
</tr>
<tr>
&LT;TD align= "center" ><%response.write "<select name=" "Lstb" "style=" "width:200" "onchange=" "SdbSortChange" (this,frmdlist.lsts); "" > "& pstr &" </select> "%>
</td>
</tr>
<tr>
&LT;TD align= "center" > </td>
</tr>
<tr>
&LT;TD align= "center" ><select style= "width:200" name= "LSTs" id= "LSTs" >
</select>
</td>
</tr>
</table>
<p align= "center" >
</p>
<p align= "center" > </p>



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.