473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How can connect 3 combo box with MYSQL by java script or ASP Classic

Hi every body

I would like connect three combo box (CascadingDropDown 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
Expand|Select|Wrap|Line Numbers
  1.  
  2. Const cServer="localhost"
  3. Const cUsername="root"
  4. Const cpassword="123"
  5. const cDatabaseName ="3combo"
  6. Const cPort = "3306"
  7.  
  8. '===========================================
  9. Dim objCon
  10. Dim strDB
  11.  
  12. Sub openDB()
  13.     strDB = "Driver=MySQL ODBC 3.51 Driver;server="&cServer&";uid="&cUsername&";Pwd="&cPassword&";database="&cDatabasename&";Port="&cPort&";Option=147456"
  14.     Set objCon = Server.CreateObject("ADODB.Connection")
  15.     objCon.open strDBEnd Sub
  16.  
  17. Sub closeDB()
  18.     objCon.Close
  19.     Set objCon = Nothing
  20. End sub
  21.  
  22. '========================================
  23. <%@ Language=VBScript %>
  24. <!--#include file="conect.asp"-->
  25.  
  26. %>
  27.  
  28. <html>
  29. <head>
  30. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  31. <title>Example combo box</title>
  32.  
  33. <script language="javascript">
  34. <!--
  35. function dept_onchange(frmSelect) {
  36.     frmSelect.submit(); 
  37. }
  38. //-->
  39. </script>
  40. </head>
  41. <body>
  42. <div align="center">The following was selected : 
  43.  
  44.   <%'=Request.Form ("courses")
  45. Dim X
  46. Dim C
  47. Dim D
  48.  
  49.  
  50. X=Request.Form ("Country2")
  51. C=Request.Form ("City2")
  52. D=Request.Form ("Destric")
  53.  
  54. Response.Write(X)
  55. Response.Write(C)
  56. Response.Write(D)
  57. %>
  58.  
  59. </div>
  60. <form name="frmSelect" method="Post" action="combo test only.asp">
  61. </p>
  62.   </div>
  63.   <table width="270" border="0" align="center" cellpadding="4" cellspacing="4">
  64.     <tr>
  65.       <td><SELECT name=Country2 id="Country2" style="width:144px;" onChange="return dept_onchange(frmSelect)" LANGUAGE=javascript>
  66.         <%
  67. Dim strSQL
  68. Dim RS
  69. strSQL= "SELECT DISTINCT Country FROM asocity ORDER BY ID"
  70. 'strSQL= "SELECT Country FROM asocity group by Country ORDER BY ID"
  71.  
  72. Call openDB
  73. Set RS=objCon.Execute(strSQL)
  74.  
  75. Do while not RS.EOF
  76. '==========================================================================
  77. if Request.Form("Country2") = RS("Country") then
  78.  
  79. Response.Write "<OPTION VALUE = '" & RS ("Country") & "' SELECTED>"
  80. Response.Write RS("Country") & "</Option>"
  81. RS.MoveNext 
  82. else
  83. Response.Write "<OPTION VALUE = '" & RS ("Country") & "'>"
  84. Response.Write RS("Country") & "</Option>"
  85. RS.MoveNext 
  86. end if
  87. loop        
  88. %></SELECT>
  89.         Country</td>
  90.     </tr>
  91.     <tr>
  92.       <td>
  93.  
  94.  
  95.  <SELECT name=City2 id="City2" style="width:144px;" onChange="return dept_onchange(frmSelect)" LANGUAGE=javascript>
  96. <%
  97. Dim strSQL2
  98. Dim RS2
  99. 'strSQL2 = "SELECT city FROM asocity Where City= '"&C&"' group by City"
  100. strSQL2 = "SELECT DISTINCT City FROM asocity Where Country= '"&X&"'"
  101. Call openDB
  102. Set RS2=objCon.Execute(strSQL2)
  103. '============================================
  104. Do while not RS2.EOF
  105. '==================================
  106. Response.write ("<option>" &RS2("City")&"</option>" ) 
  107. RS2.MoveNext
  108. loop
  109.  
  110. 'if Request.Form("City2") = RS2("City") then
  111. 'Response.Write "<OPTION VALUE = '" & RS2 ("City") & "' SELECTED>"
  112. 'Response.Write RS2("City") & "</Option>"
  113. 'RS2.MoveNext 
  114. 'else
  115. 'Response.Write "<OPTION VALUE = '" & RS2 ("City") & "'>"
  116. 'Response.Write RS2("City") & "</Option>"
  117. 'RS2.MoveNext 
  118. 'end if
  119. 'loop        
  120. %>
  121.       </SELECT>
  122.  City</td>
  123.     </tr>
  124.     <tr>
  125.       <td><select name="Destric" style="width:144px;" id="Destric">
  126.         <%
  127. Dim strSQL3
  128. Dim RS3
  129.  
  130. strSQL3 = "SELECT username FROM asocity Where city= '"&C&"'"
  131.  
  132. 'strSQL3 = "SELECT DISTINCT username FROM asocity Where Country= '"&X&"' ORDER BY ID"
  133.  
  134.  
  135. Call openDB
  136. Set RS3=objCon.Execute(strSQL3)
  137.  
  138. Do while not RS3.EOF
  139. Response.write ("<option>" &RS3("username")&"</option>") 
  140. RS3.MoveNext 
  141. loop
  142. %>
  143.       </SELECT>
  144.         Destric</td>
  145.     </tr>
  146.     <tr>
  147.       <td width="254"><input type="submit" name="Submit" value="Add"></td>
  148.     </tr>
  149.   </table>
  150.   <p>&nbsp;</p>
  151.   <p>&nbsp;</p>
  152.  
  153.  
  154.   <div align="center">
  155.     <%
  156.  Dim akm
  157.  akm=Request.Form("txtArea7")
  158.  
  159.  if akm="" then
  160.  akm="0000000000000"
  161.  end if
  162.  
  163.  IF Request.Form("Submit")="Add" then
  164.  Response.write (X)+"<BR>"
  165.  Response.write (C)+"<BR>"
  166.  Response.write (akm) 
  167.  End if
  168.  %>
  169.   </div>
  170. </form>
  171.  
  172.  
  173. </body>
  174. </html>
Attached Files
File Type: zip Exam.zip (10.3 KB, 315 views)
Aug 31 '09 #1
3 5495
jhardman
3,406 Expert 2GB
just trying to make sure I understand you - you say that after the user makes one selection you want to move the cursor to another <select> box?

Jared

BTW, please put your code in [ code] [/ code] tags, it makes it much more readable
Sep 1 '09 #2
Yes I want move a cursor to select a city , for example when I Select Berlin , in combobox2 , stop the cursor in the Berlin City.
For Example:
Combo box 1 : Country : Germany
Combo box 2 : City : Berlin
Combo box 3: State : G1


For More detail :
When I Select Germany in the Country Combo box 1, Show all City of Germany in the Next Combo box (Combo box2) , and when I Select Berlin in the ( Combo box2) , Return the cursor to Hamborg City ??? I have a problem in (combo box2) ?
Thanks for response us.
Sep 1 '09 #3
jhardman
3,406 Expert 2GB
OK, this is a fairly common problem, moving the cursor is going to have to be done with javascript, there's no way around that. ASP only works on the server, all ASP code is inactive by the time it gets to the user. The code to move a dursor is going to be something like this:
Expand|Select|Wrap|Line Numbers
  1. <select name="country" onSelect="this.form.city.focus()">
  2. '...
  3. </select>
  4. <select name="city">
Does this make sense? It's been a while since I've done javascript, but it's something like that.

The other part of the question you seem to be asking is how to limit the results of the second select based on the first choice, so if the user chooses "germany" in the first box, he sees "Berlin, Hamburg, etc" in the second. As I mentioned earlier, the ASP code is inactive by the time it gets to the client's browser, so if you want to use ASP to limit the options in the second select box, you need to submit the form (onSelect="this.form.submit()") and then use asp to resend the form with the new data in place in the second box. Does this make sense? If you need help with any part of this task, please ask.

On the other hand, this might slow down the user's experience, and although I've seen plenty of professional sites that use this method, a lot of people use a pure javascript technique wherein all of the possibilities are sent to the user, and after the selection is made a javascript function alters the second select box accordingly. You will have to ask a javascript expert for that method.

There is also one other possibility, the technology "Ajax" was invented to handle exactly this type of issue, and it can communicate back to the server to refresh the list for the second select in real time. This is probably the preferred method nowadays.

Jared
Sep 6 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: Mr Dygi | last post by:
Hi, PHP 4.3.4 installed manually from package *.zip and Apache 2. I have a problem with this simple code: <?php $link = mysql_connect("127.0.0.1","","") or die("Could not connect: " ....
2
by: pieter_hordijk | last post by:
Hi all, maybe this isn't a php question, but a MySQL question. If so I'm sorry for asking you guys to help me :) I know this question is asked often in NGs, but I couldn't find the answer...
0
by: D. K. | last post by:
Hi; I have installed suse 8.2 a short while ago and at my first attempt to connect mysql (via shell and a perl dbi script) i get following error: can't connect to mysql server through socjet...
0
by: Denis Labon | last post by:
I can't connect to mysql server using the mysql-connector-java-3.0.11. I was able to run the same program when I was running Suse 9.0 but since I install Suse 9.1, I can't connect. The error...
5
by: Ike | last post by:
Through Java, I am attempting to connect to a MySQL 4.12 server on a remote computer. I can connect fine via php. I cann connect fine via Java, through a servlet, when the servlet is on the same...
1
by: iceboy | last post by:
Hello to all,I have a problem to connect PHP & MySQL together. I have created a form that gets the username & password from admin and connect him to database.the part of PHP script that connect to...
5
by: Ankur | last post by:
Hi Folks, I am new for this group. I want to clarify one thing what's a basic difference between Client Side Java Script and Server Side Java Script. how we can differentiate it. Why we called...
2
by: hkma08 | last post by:
I dont know I should post JSP error in here or not. If not please redirect me to another one. Thx. I just installed apache tomcat with mysql with java, but i got error when try to connect to mysql...
3
by: Anthony Jones | last post by:
"paulmitchell507" <paulmitchell507@googlemail.comwrote in message news:effe22fb-7c85-4172-953d-d6546cd548f8@c58g2000hsc.googlegroups.com... On Aug 12, 1:06 pm, "Anthony Jones"...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.