473,765 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

3 New Member
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
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 5513
jhardman
3,406 Recognized Expert Specialist
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
alandiit
3 New Member
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 Recognized Expert Specialist
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
4822
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: " . mysql_error()); echo "Connected successfully"; mysql_close($link);
2
4503
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 that works for me. I've just installed my server with following:
0
623
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 '/var/lib/mysql/mysql.sock'. i know this looks like a common error and I am terribly sorry if this kind of subject has been posted before but I'll appreciate any urgent help. Thanks Devrim ...
0
421
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 message is: java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused I'm using mysql-standard-4.0.14 and able to get in the mysql server by typing: bin/mysql -uroot -ptest
5
3854
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 machine (localhost) as the MySQL DB. However, when they are on different machines with different IPs, calling across the Internet (and there are no firewall issues -- I can connect fine to the remote MySQL DB via php from the same machine, not...
1
4134
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 mysql is as follow: $db=mysql_pconnect("hostname",$username,$password); if(!$db){ echo"ERROR:connecting failed"; exit; } else echo"you have connected to database succsessfully"; I want to know what should i write instead of "hostname"...
5
13123
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 this kind of script "Server Side Java Script". I am in confusion because according to lots of web developer Java Script is a client side scripting language. We can not say it Server Side Java Script.
2
1993
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 database, what is happening? Here is my error msg: org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 3 in the jsp file: /tutorial/test.jsp Syntax error on tokens, delete these tokens <%@ page...
3
5070
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" <A...@yadayadayada.comwrote: Paul, When you ask for help you will most likely get responses that ask you questions so that what you are doing is better understood and the help can be more targeted. Its very frustating trying to help someone when they won't...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10156
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9951
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7375
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.