473,396 Members | 1,812 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,396 software developers and data experts.

One list box selection should decide another 2 list box items

hi,
Any one can give me the best solution of it with easiest codings for ASP and access.

First list box selection should decide the another two list boxes of the same items.

I have used 2 list box. Country and state. If i will select the country India and select all the states. if i will select other country diplay that county's states. plz help me
Feb 4 '08 #1
1 1269
CroCrew
564 Expert 512MB
Hello silvia21,

I don’t know if this is the best solution. But, it is one option. In this example the Access database (MyDatabase.mdb) has two tables (Countries and Territories). You can extend the database schema if need be.

The table {Countries} just has two fields one called {CountryID} and the other is {CountryName}. {CountryID} is an auto incrementing field and {CountryName} is a text field that stores the name of a country.

The table {Territories} has two fields also; one called {CountryID} is a number field that is used to link the two tables together. The other field is {TerritoryName} and that is a text field that stores the name of a State or Province.

Let me know if I need to explain the relationship between the two tables more. For now I will assume that you understand the database part of this example.

Both Access Database and ASP file in this example are in the same folder.

Here is the example page called “Example.asp” (without the quotes):
Expand|Select|Wrap|Line Numbers
  1. <%
  2.     Set Conn = Server.CreateObject("ADODB.Connection")
  3.     Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("MyDatabase.mdb") 
  4.  
  5.     Set rsCountries = Server.CreateObject("ADODB.Recordset") 
  6.         SQL = "SELECT * FROM Countries"
  7.     rsCountries.Open SQL, Conn
  8.  
  9.     If (Len(Request.Form("CountryID")) > 1) Then
  10.         SQL = "SELECT * FROM Territories"
  11.     Else
  12.         SQL = "SELECT * FROM Territories WHERE CountryID = '" & Request.Form("CountryID") & "'"
  13.     End If
  14.  
  15.     Set rsTerritories = Server.CreateObject("ADODB.Recordset") 
  16.     rsTerritories.Open SQL, Conn
  17. %>
  18. <html>
  19.     <head>
  20.         <title>Example</title>
  21.     </head>
  22.     <body>
  23.         <table border="0">
  24.             <form method="post" action="Example.asp" name="xform">
  25.                 <select name="CountryID" size="1" onchange="document.xform.submit();">
  26.                     <%Do Until (rsCountries.EOF)%>
  27.                         <option value="<%Response.Write(rsCountries("CountryID"))%>"<%If (Request.Form("CountryID")=rsCountries("CountryID")) Then%> selected<%End If%>><%Response.Write(rsCountries("CountryName"))%></option>
  28.                         <%rsCountries.MoveNext%>
  29.                     <%Loop%>
  30.                 </select>
  31.                 <select name="Territories" size="1">
  32.                     <%Do Until (rsTerritories.EOF)%>
  33.                         <option value="<%Response.Write(rsTerritories("TerritoryName"))%>"><%Response.Write(rsTerritories("TerritoryName"))%></option>
  34.                         <%rsTerritories.MoveNext%>
  35.                     <%Loop%>
  36.                 </select>
  37.             </form>
  38.         </table>
  39.     </body>
  40. </html>
  41. <%
  42.     rsCountries.close
  43.     rsTerritories.close
  44.     Conn.close
  45. %>
  46.  
  47.  
Hope this helps out~
Feb 5 '08 #2

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

Similar topics

4
by: Jesse Noller | last post by:
Hello - I'm probably missing something here, but I have a problem where I am populating a list of lists like this: list1 = list2 = list3 = main_list =
4
by: Colleyville Alan | last post by:
I am trying to use a list box to allow users to select items, the results are queried based on the selection and written to a spreadsheet. If the item already exists on their current spreadsheet,...
4
by: Paul | last post by:
Hi, When should I use a list (in table properties: like Ford;Mercedes;BMW;Audi ) and when should I use a lookup table?? And second question: IF I use a lookup table, should I always make a...
2
by: Peter | last post by:
Hello! Please, could anyone tell, is it possible to set multiple items to be selected in list control in the code? For example when the web form is loaded three items of 5 are selected in list...
0
by: Brian Henry | last post by:
Since no one else knew how to do this I sat here all morning experimenting with this and this is what I came up with... Its an example of how to get a list of items back from a virtual mode list...
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
13
subashini Thiyagarajan
by: subashini Thiyagarajan | last post by:
Hi, I am inserting a record in Access table using ASP,it is working fine.i have so many text boxes,list boxes to get the input fields. Actually for all the insert cases i don't require all the...
4
subashini Thiyagarajan
by: subashini Thiyagarajan | last post by:
hi, Any one can give me the best solution of it with easiest codings for ASP and access. First list box selection should decide the another two list boxes of the same items. i need to populate...
5
Claus Mygind
by: Claus Mygind | last post by:
I have a list box and want to limit the user to selecting a max of 5 items from the list. I've put in a counter which warns the user that more than 5 items have been selected, however I cannot...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
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...
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
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,...

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.