473,472 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to synchronize two list/menu form fields in ASP

87 New Member
Greetings,

I am using Dreamweaver CS3 to design an ASP page that contains a Record Insertion Form. Within this form are two list/menu form fields that I would like to "synchronize". In other words, let's say I have two menus: one where the user selects "Calendar Quarter" and a second for selecting "Calendar Month". If the user selects "Q1" from the first menu, then the second menu is requeried and "refreshed" to show only the months "Jan.", "Feb". and "Mar."

I know how to do this using VisualBasic for MS Access forms but am not sure how to accomplish this for ASP.

Any advice or suggestions would be most welcome.

- JM
Apr 18 '08 #1
13 3677
jhardman
3,406 Recognized Expert Specialist
The problem is that ASP is strictly a server-side technology, it ceases to work as soon as the page is loaded onto the browser. For that you will need at least some client-side scripting. There are two ways I often see this done, both involve some javascript and your choice depends largely on how much javascript you want to use. Here are the options:

1 - when you make the first selection use a very brief function to submit the form as it is so far (not much javascript, right? the rest is done in ASP). The form handler (preferably this same ASP page) should re-populate the form and send it right back to the user (hopefully fast enough that he doesn't realize he has submitted anything) with the inputs he has already entered filled out and the select in question changed to the months available.

2 - Make several versions of the second select, and all of them should be hidden. On the onChange event of the first drop-down, unhide the appropriate version of the second drop-down and rehide all the others.

I've seen both of these methods used well on live web sites. Let me know if this helps.

Jared
Apr 21 '08 #2
jeffstl
432 Recognized Expert Contributor
Greetings,

I am using Dreamweaver CS3 to design an ASP page that contains a Record Insertion Form. Within this form are two list/menu form fields that I would like to "synchronize". In other words, let's say I have two menus: one where the user selects "Calendar Quarter" and a second for selecting "Calendar Month". If the user selects "Q1" from the first menu, then the second menu is requeried and "refreshed" to show only the months "Jan.", "Feb". and "Mar."

I know how to do this using VisualBasic for MS Access forms but am not sure how to accomplish this for ASP.

Any advice or suggestions would be most welcome.

- JM
Are you using classic ASP ? (Response.write Variable)

Or are you using ASP.NET? (web controls such as <asp: Datagrid> , etc

If you are using asp.net what you describe can be accomplished, indirectly since .net pages do not reload the entire page but only send data back and forth.

There are probably asp.net calander controls out there, or add ons for dreamweaver.

If you are in fact using classic ASP however what jh said is correct, you will need to use javascript to implement something like that that happens right in front of the user working with the interface, without reloading the entire page, or opening new windows, etc.
Apr 21 '08 #3
jmartmem
87 New Member
I think your second option is probably the easier of the two, given my limited ASP experience. Could you perhaps point me in the direction of sample code where you've seen this done? While I understand the concept, I'm not sure how to accomplish this in Dreamweaver CS3 or by back-end coding.

Any examples you may have would be most helpful.

- JM
Apr 21 '08 #4
jhardman
3,406 Recognized Expert Specialist
I think your second option is probably the easier of the two, given my limited ASP experience. Could you perhaps point me in the direction of sample code where you've seen this done? While I understand the concept, I'm not sure how to accomplish this in Dreamweaver CS3 or by back-end coding.

Any examples you may have would be most helpful.

- JM
I don't have any dreamweaver experience, and although I have gotten this type of dealy to work, but I don't consider myself a javascript expert, so I don't feel like I'm qualified to give code on how it is done. I'll ask a javascript expert to look in on this thread.

Jared
Apr 21 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
There is a third option: Ajax. This would avoid the need to load all the select options at the beginning.

However, if you are going for the second option, this link should help. You could also use the select add() method (though IE is different from other browsers, as usual).
Apr 22 '08 #6
jmartmem
87 New Member
Several months ago, I started this thread. Over time, I've changed the direction I want to take.

What I'm seeking now is further advice on how to accomplish the following (which I've copied from an earlier post on this thread):

1 - when you make the first selection use a very brief function to submit the form as it is so far (not much javascript, right? the rest is done in ASP). The form handler (preferably this same ASP page) should re-populate the form and send it right back to the user (hopefully fast enough that he doesn't realize he has submitted anything) with the inputs he has already entered filled out and the select in question changed to the months available.
Whatever Web or other resources anyone can suggest would be most appreciated.

- JM
Jun 23 '08 #7
DrBunchman
979 Recognized Expert Contributor
Hi JM,

In the onclick event of your first drop down you can fire off a function which will redirect the page to itself and pass your selected value through the querystring. You can then use this value to populate your second drop down. Here's an example:
Expand|Select|Wrap|Line Numbers
  1.  <head> 
  2.   function Reload(form)
  3.   {
  4.     var dd1=form.Title.options[form.dd1.options.selectedIndex].value;
  5.     self.location='ThisPage.asp?dd1=' + dd1;
  6.   }
  7. </head>
  8. <body>
  9. <form>
  10. <select name="dd1" onchange="Reload(this.form)">
  11.     <option value="1">Option 1</option>
  12.     <option value="2">Option 2</option>
  13. </select>
  14. <%
  15. Dim dd1
  16. dd1 = Request.Querystring("dd1")
  17. %>
  18. </form>
  19. </body>
  20.  
Can you see how this example works? I haven't written any code for the second drop down but all you'd need to do is use the value of dd1 to populate it as required.

Let me know if this helps,

Dr B
Jun 24 '08 #8
jmartmem
87 New Member
Well, it helps me get farther than I was this morning, but I still have a ways to go.

Let me back up: what I want is two list boxes filled with values from a query, and the selection from the 1st list box results in a filtered 2nd list box.

Here's the code for what I have so far:

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language=JavaScript>
  2. function reload(form){
  3. var workstream01=form.workstream01.options[form.workstream01.options.selectedIndex].value;
  4. self.location='TEST_query.asp?workstream01=' + workstream01 ;
  5. }
  6. </script>
  7.  
  8. <%
  9. Dim workstream01
  10. workstream01=Request.QueryString("workstream01") 
  11. %>
  12.  
  13. <form id="form1" name="form1" method="post" action="">
  14.   <p>
  15.  
  16. <%
  17. 'FIRST DROP DOWN LIST
  18. Dim mySQL1, myRS1, ddworkstream01
  19.  
  20. Set myRS1 = Server.CreateObject("ADODB.Recordset")
  21. mySQL1 = "SELECT Workstream FROM XREF_WORKSTREAMS ORDER BY WorkFlow"
  22. myRS1.Open mySQL1, myConn, adOpenKeyset, adLockOptimistic 
  23. 'Response.Write "<select name=workstream01 onchange="Reload(this.form)"><option value='''' selected>Select Workstream</option>"
  24.  
  25. Response.Write "<form method=post name=form1 action=''><select name=workstream01 onchange='reload(this.form)'><option value=''>Select Workstream</option>"
  26.  
  27. Do While Not myRS1.EOF 
  28. Response.Write "<option value=''" & myRS1("Workstream") &"''>"& myRS1("Workstream") &"</option>"
  29. myRS1.MoveNext
  30. Loop
  31. Response.Write "</select>"
  32. myRS1.Close
  33. Set myRS1 = Nothing 
  34. %>
  35.   </p>
  36.   <p>
  37.  
  38.  
  39. <%
  40. 'SECOND DROP DOWN LIST
  41. Dim mySQL2, myRS2
  42.  
  43. 'If len(workstream_01) > 1 Then
  44.  
  45. Set myRS2 = Server.CreateObject("ADODB.Recordset")
  46. 'mySQL2 = "SELECT Program_Name FROM EZTracking_MASTER WHERE EZ_Strategic_Workstream='" & workstream01 & "' GROUP BY Program_Name ORDER BY Program_Name"
  47. mySQL2 = "SELECT Program_Name FROM EZTracking_MASTER GROUP BY Program_Name ORDER BY Program_Name"
  48. myRS2.Open mySQL2, myConn, adOpenKeyset, adLockOptimistic 
  49. 'Response.Write "<select name=workstream01 onchange="Reload(this.form)"><option value='''' selected>Select Workstream</option>"
  50.  
  51. Response.Write "<form method=post name=form1 action=''><select name=program_name01'><option value=''>Select Program Name</option>"
  52.  
  53. Do While Not myRS2.EOF 
  54. Response.Write "<option value=''" & myRS2("Program_Name") &"''>"& myRS2("Program_Name") &"</option>"
  55. myRS2.MoveNext
  56. Loop
  57. Response.Write "</select>"
  58. myRS2.Close
  59. 'end if
  60. Set myRS2 = Nothing 
  61. %>
  62.  
  63.  
  64.   &nbsp;  </p>
  65. </form>
As it stands now, the above code correctly populates the two list boxes and reloads the form when selecting from the first list box, but I've yet to get it to reload the page, keep the variable from the 1st list box and filter the 2nd list box.

One person suggested doing a "mini-submit" through an onchange event when the first list box selection is made, but I'm not sure how to accomplish that either.

I know I'm missing something but I can't figure out what it is. This is a problem I need to fix, so your help would be greatly appreciated.

JM
Jun 24 '08 #9
DrBunchman
979 Recognized Expert Contributor
I can't see anything obvious so the next step is to try to debug this to see where the problem lies. First of all try putting a messagebox in your javascript function to check it is being called correctly (alert('Test'); or something like that). Then put some Response.Write's on the page to test whether the value from the first dropdown list is being correctly passed back.

Let me know what happens,

Dr B
Jun 25 '08 #10
jmartmem
87 New Member
The alert('test') fires correctly onchange, but the value isn't getting passed back. I'll keep de-bugging, but am not sure what the problem is.
Jun 30 '08 #11
jmartmem
87 New Member
I'm posting some more code below because my inability to pass the variable back is getting extremely frustrating!

Expand|Select|Wrap|Line Numbers
  1. <%@ Language = VBscript %>
  2. <% Option Explicit %>
  3. <!--#include file="Connections/EZTrackingTool.asp" -->
  4. <!-- #include virtual = "/adovbs.inc" -->
  5. <% Response.Buffer = True %>
  6.  
  7. <html>
  8. <head>
  9. <title>Database Search</title>
  10. <SCRIPT language=JavaScript>
  11. function reload(form){
  12. var val=form.workstream01.options[form.workstream01.options.selectedIndex].value;
  13. self.location='TEST_query2.asp?workstream01=' + val ;
  14. alert('TEST')
  15. }
  16. </script>
  17. </head><body>
  18.  
  19. <%
  20. Dim objconn,objRS,strSQL,ws
  21. ws=Request.QueryString("workstream01")
  22. Set objconn = Server.CreateObject("ADODB.Connection")
  23. objconn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/ez/Database/TrackingToolDB.mdb")
  24. objconn.Open
  25.  
  26. Set objRs = Server.CreateObject("ADODB.Recordset")
  27.  
  28. '''''First drop down list starts here'''''
  29.  
  30. strSQL = "SELECT WorkFlow from XREF_WORKSTREAMS ORDER BY WorkFlow"
  31. objRS.Open strSQL, objconn
  32. Response.Write "<form method=post name=f1 action=''><select name=workstream01 onchange='reload(this.form)'><option value=''>Select Workstream</option>"
  33. Do While Not objRS.EOF 
  34.     Response.Write "<option value=" & objRs("WorkFlow") & ">" & objRs("WorkFlow") & "</option>"
  35.      objRS.MoveNext
  36.  Loop
  37. objRs.Close
  38. Response.Write "</select>"
  39. Response.Write "<br>----<br>"
  40.  
  41. ''' Second list starts here ''''
  42.  
  43. If len(ws) > 1 Then
  44.  
  45. strSQL = "SELECT * FROM XREF_WORKSTREAMS where Workstream='" & ws &"'"
  46. objRS.Open strSQL, objconn
  47.  
  48. Do While Not objRS.EOF 
  49.     Response.Write objRs("Workstream") & " " & objRs("WorkFlow") & "  "  & objRs("Definition") & "<br>"
  50.      objRS.MoveNext
  51.  Loop
  52. Response.Write "</form>"
  53. objRs.Close
  54.  
  55. objconn.Close
  56. end if 
  57.  
  58.      %>
  59. </body>
  60. </html>
As I mentioned before, the alert popup for the javascript function works fine. The value selected in the first drop down gets passed to the query string. But the Response.Write to the page in the second list does not happen.

I would also prefer that the first drop down retain the value selected after the onchange function, but am also unable to make this happen.

HELP PLEASE!

- JM
Jun 30 '08 #12
DrBunchman
979 Recognized Expert Contributor
JM, change the alert to alert(val); so you can see whether the value of the drop down is being assigned to the variable correctly.

Let me know what happens,

Dr B
Jul 1 '08 #13
jmartmem
87 New Member
It appears to work fine. I put the value in the javascript alert...

Expand|Select|Wrap|Line Numbers
  1. alert(form.workstream01.options[form.workstream01.options.selectedIndex].value)
...and the alert value returned is the same one selected in the 'workstream01' drop down list.

Anything else I should look at?
Jul 1 '08 #14

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

Similar topics

2
by: Adam Smith | last post by:
I am developing a Form to be used for data input into a database. To limit errors in fields I want to input some data using "<SELECT NAME=xxxxx> <OPTIONS VALUE=yyyyy> <OPTIONS VAL........> ..........
4
by: justin tyme | last post by:
Hello Experts! I would like to combine (which may not be the correct technical term) two text fields from the same table in a query. Specifically, text field A and text field B are both lists of...
1
by: platostoteles | last post by:
Hallo NG, I am new to JavaScript and would really appreciate any help to solve my problem. I am using the blow code in my form to validate form fields. What I would like to accomplish is that...
6
by: AA Arens | last post by:
Hi, I have a database with 2 main forms. Contacts and companies. I share the base with two others via LAN. On the companies form I have buttons to navigate throught the records (>400). We are...
2
by: Infopumper | last post by:
:mad: OK. I have been attempting to do this for some time: Dynamic List/Menu Dropdiwn with Usernames Need to update Record Using the Dropdown Using ASP, VB, And Dreamweaver Form Code: <form...
6
by: mcgrew.michael | last post by:
I hope this is the right group. I am very new to ASP so this is probably a stupid question. I have some vbscript that query's AD and populates a recordset. I know the recorset contains the...
1
by: EyeHawk | last post by:
OK, hopefully somebody can help me out again. My next problem is updating 3 form fields (type list/menu option) that correspond to a date, one for month, one for day and one for year when the user...
4
by: jmartmem | last post by:
Greetings, I have an ASP page containing a Record Insertion Form with a number of fields (mostly text fields and list/menu fields) linked to an Access database. I've created an onsubmit behavior...
1
by: jmartmem | last post by:
Greetings, I have a nagging problem with client-side dynamic dependent list boxes that perhaps someone can help me troubleshoot. I have a form with a series of dynamic dependent list boxes....
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
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
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,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.