<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="config.inc.asp" -->
<%
set reg = Server.CreateObject("ADODB.Recordset")
reg.ActiveConnection = ConnString
reg.Source = "SELECT * FROM Country"
reg.CursorType = 0
reg.CursorLocation = 2
reg.LockType = 3
reg.Open()
reg_numRows = 0
%>
<html>
<head>
<title>Database-driven Dynamic Drop-down Menu</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var NoArray = new Array("('Select City','',true,true)");
<%
While (NOT reg.EOF)
%>
var <% response.write(reg.Fields.Item("CountryName").Value) &"Array"%> = new Array("('Select City','',true,true)",
<%
TempRegCode = (reg.Fields.Item("CountryName").Value)
set ctry = Server.CreateObject("ADODB.Recordset")
ctry.ActiveConnection = ConnString
ctry.Source = "SELECT * FROM City WHERE CountryName='" &TempRegCode &"' Order By CityName"
ctry.CursorType = 0
ctry.CursorLocation = 2
ctry.LockType = 3
ctry.Open()
ctry_numRows = 0
While (NOT ctry.EOF)
response.write ("""('") &(ctry.Fields.Item("CityName").Value) &"','" &(ctry.Fields.Item("CityName").Value) &"')"%>"<%
ctry.MoveNext()
If NOT ctry.EOF then
response.write ","
Else
response.write ");"
End If%>
<%
' ctry.MoveNext()
Wend
If (ctry.CursorType > 0) Then
ctry.MoveFirst
Else
ctry.Requery
End If
%>
<%
reg.MoveNext()
Wend
If (reg.CursorType > 0) Then
reg.MoveFirst
Else
reg.Requery
End If
%>
function populateCity(inForm,selected) {
var selectedArray = eval(selected + "Array");
while (selectedArray.length < inForm.City.options.length) {
inForm.City.options[(inForm.City.options.length - 1)] = null;
}
for (var i=0; i < selectedArray.length; i++) {
eval("inForm.City.options=" + "new Option" + selectedArray);
}
if (inForm.Country.options[0].value == '') {
inForm.Country.options[0]= null;
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0);
}
else {
if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
window.history.go(0);
}
}
}
}
}
// End -->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="globe" action="Default.asp" method="post">
<select name="Country" onChange="populateCity(document.globe,document.globe.Country.options[document.globe.Country.selectedIndex].value)">
<option value=http://www.webdeveloper.com/forum/archive/index.php/"No" selected>Select Country</option>
<%
While (NOT reg.EOF)
%>
<option value="<%=(reg.Fields.Item("CountryName").Value)%>"><%=(reg.Fields.Item("CountryName").Value)%></option>
<%
reg.MoveNext()
Wend
If (reg.CursorType > 0) Then
reg.MoveFirst
Else
reg.Requery
End If
%>
</select>
<select name="City">
<option value=''>Select City</option>
</select>
</form>
</body>
</html>
<%
ctry.Close()
%>
<%
reg.Close()
%>
<!--#include file="config.inc.asp" -->
<%
set reg = Server.CreateObject("ADODB.Recordset")
reg.ActiveConnection = ConnString
reg.Source = "SELECT * FROM Country"
reg.CursorType = 0
reg.CursorLocation = 2
reg.LockType = 3
reg.Open()
reg_numRows = 0
%>
<html>
<head>
<title>Database-driven Dynamic Drop-down Menu</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var NoArray = new Array("('Select City','',true,true)");
<%
While (NOT reg.EOF)
%>
var <% response.write(reg.Fields.Item("CountryName").Value) &"Array"%> = new Array("('Select City','',true,true)",
<%
TempRegCode = (reg.Fields.Item("CountryName").Value)
set ctry = Server.CreateObject("ADODB.Recordset")
ctry.ActiveConnection = ConnString
ctry.Source = "SELECT * FROM City WHERE CountryName='" &TempRegCode &"' Order By CityName"
ctry.CursorType = 0
ctry.CursorLocation = 2
ctry.LockType = 3
ctry.Open()
ctry_numRows = 0
While (NOT ctry.EOF)
response.write ("""('") &(ctry.Fields.Item("CityName").Value) &"','" &(ctry.Fields.Item("CityName").Value) &"')"%>"<%
ctry.MoveNext()
If NOT ctry.EOF then
response.write ","
Else
response.write ");"
End If%>
<%
' ctry.MoveNext()
Wend
If (ctry.CursorType > 0) Then
ctry.MoveFirst
Else
ctry.Requery
End If
%>
<%
reg.MoveNext()
Wend
If (reg.CursorType > 0) Then
reg.MoveFirst
Else
reg.Requery
End If
%>
function populateCity(inForm,selected) {
var selectedArray = eval(selected + "Array");
while (selectedArray.length < inForm.City.options.length) {
inForm.City.options[(inForm.City.options.length - 1)] = null;
}
for (var i=0; i < selectedArray.length; i++) {
eval("inForm.City.options=" + "new Option" + selectedArray);
}
if (inForm.Country.options[0].value == '') {
inForm.Country.options[0]= null;
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0);
}
else {
if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
window.history.go(0);
}
}
}
}
}
// End -->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="globe" action="Default.asp" method="post">
<select name="Country" onChange="populateCity(document.globe,document.globe.Country.options[document.globe.Country.selectedIndex].value)">
<option value=http://www.webdeveloper.com/forum/archive/index.php/"No" selected>Select Country</option>
<%
While (NOT reg.EOF)
%>
<option value="<%=(reg.Fields.Item("CountryName").Value)%>"><%=(reg.Fields.Item("CountryName").Value)%></option>
<%
reg.MoveNext()
Wend
If (reg.CursorType > 0) Then
reg.MoveFirst
Else
reg.Requery
End If
%>
</select>
<select name="City">
<option value=''>Select City</option>
</select>
</form>
</body>
</html>
<%
ctry.Close()
%>
<%
reg.Close()
%>