Hi every body
I would like connect three combo box (CascadingDropDo wn with a Database) MYSQL by asp classic or Java Script .
But I have a problem with this example , when I will change City , returen the curser to the old select -City .
Can you Solve this problem for me.
Thanks
I would like connect three combo box (CascadingDropDo wn with a Database) MYSQL by asp classic or Java Script .
But I have a problem with this example , when I will change City , returen the curser to the old select -City .
Can you Solve this problem for me.
Thanks
Code:
Const cServer="localhost"
Const cUsername="root"
Const cpassword="123"
const cDatabaseName ="3combo"
Const cPort = "3306"
'===========================================
Dim objCon
Dim strDB
Sub openDB()
strDB = "Driver=MySQL ODBC 3.51 Driver;server="&cServer&";uid="&cUsername&";Pwd="&cPassword&";database="&cDatabasename&";Port="&cPort&";Option=147456"
Set objCon = Server.CreateObject("ADODB.Connection")
[B]objCon.open strDB[/B]End Sub
Sub closeDB()
objCon.Close
Set objCon = Nothing
End sub
'========================================
<%@ Language=VBScript %>
<!--#include file="conect.asp"-->
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Example combo box</title>
<script language="javascript">
<!--
function dept_onchange(frmSelect) {
frmSelect.submit();
}
//-->
</script>
</head>
<body>
<div align="center">The following was selected :
<%'=Request.Form ("courses")
Dim X
Dim C
Dim D
X=Request.Form ("Country2")
C=Request.Form ("City2")
D=Request.Form ("Destric")
Response.Write(X)
Response.Write(C)
Response.Write(D)
%>
</div>
<form name="frmSelect" method="Post" action="combo test only.asp">
</p>
</div>
<table width="270" border="0" align="center" cellpadding="4" cellspacing="4">
<tr>
<td><SELECT name=Country2 id="Country2" style="width:144px;" onChange="return dept_onchange(frmSelect)" LANGUAGE=javascript>
<%
Dim strSQL
Dim RS
strSQL= "SELECT DISTINCT Country FROM asocity ORDER BY ID"
'strSQL= "SELECT Country FROM asocity group by Country ORDER BY ID"
Call openDB
Set RS=objCon.Execute(strSQL)
Do while not RS.EOF
'==========================================================================
if Request.Form("Country2") = RS("Country") then
Response.Write "<OPTION VALUE = '" & RS ("Country") & "' SELECTED>"
Response.Write RS("Country") & "</Option>"
RS.MoveNext
else
Response.Write "<OPTION VALUE = '" & RS ("Country") & "'>"
Response.Write RS("Country") & "</Option>"
RS.MoveNext
end if
loop
%></SELECT>
Country</td>
</tr>
<tr>
<td>
<SELECT name=City2 id="City2" style="width:144px;" onChange="return dept_onchange(frmSelect)" LANGUAGE=javascript>
<%
Dim strSQL2
Dim RS2
[B]'strSQL2 = "SELECT city FROM asocity Where City= '"&C&"' group by City"
strSQL2 = "SELECT DISTINCT City FROM asocity Where Country= '"&X&"'"[/B]
Call openDB
Set RS2=objCon.Execute(strSQL2)
'============================================
[B]Do while not RS2.EOF
'==================================
Response.write ("<option>" &RS2("City")&"</option>" )
RS2.MoveNext
loop[/B]
'if Request.Form("City2") = RS2("City") then
'Response.Write "<OPTION VALUE = '" & RS2 ("City") & "' SELECTED>"
'Response.Write RS2("City") & "</Option>"
'RS2.MoveNext
'else
'Response.Write "<OPTION VALUE = '" & RS2 ("City") & "'>"
'Response.Write RS2("City") & "</Option>"
'RS2.MoveNext
'end if
'loop
%>
</SELECT>
City</td>
</tr>
<tr>
<td><select name="Destric" style="width:144px;" id="Destric">
<%
Dim strSQL3
Dim RS3
strSQL3 = "SELECT username FROM asocity Where city= '"&C&"'"
'strSQL3 = "SELECT DISTINCT username FROM asocity Where Country= '"&X&"' ORDER BY ID"
Call openDB
Set RS3=objCon.Execute(strSQL3)
Do while not RS3.EOF
Response.write ("<option>" &RS3("username")&"</option>")
RS3.MoveNext
loop
%>
</SELECT>
Destric</td>
</tr>
<tr>
<td width="254"><input type="submit" name="Submit" value="Add"></td>
</tr>
</table>
<p> </p>
<p> </p>
<div align="center">
<%
Dim akm
akm=Request.Form("txtArea7")
if akm="" then
akm="0000000000000"
end if
IF Request.Form("Submit")="Add" then
Response.write (X)+"<BR>"
Response.write (C)+"<BR>"
Response.write (akm)
End if
%>
</div>
</form>
</body>
</html>
Comment