Solved

Populate subsequent combo boxes using recordset

Posted on 2007-12-05
9
1,092 Views
Last Modified: 2008-03-15
MS Access, ASP, Dreamweaver 8.
I've found several postings relating to my topic, but none have struck me as exactly what I'm looking for. Then again, ASP database code is really new to me.

im trying to develop a small mileage tool, but I'm having trouble figuring out where to start. database is just 1 table named "addresses" with 4 fields:

ID_no : Autonumber
Sitecode : Text
Location : Text
Address : Text

on the .asp page, i have 2 combo boxes (1 for sitecode, 1 for location, as some customers have multiple offices). step 1 is to select the sitecode from combo 1, at which point i would like combo 2 to update itself with all the locations that match the sitecode from combo 1. then, click submit and add text regarding the location and the mileage (obtained from google maps). so far, the closest code (from a post by fritz_the_blank) to populate a combo box from a database, yields "Expected 'end'" error.
<%

		set con = server.createObject("adodb.connection")

		set rs = server.createObject("adodb.recordset")

		con.open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db.mdb")

		rs.open "select Sitecode from addresses",con

		with rs

		response.write("<select name = 'sitecode'>")

		 do until .eof

		%>

		<option value = <%=.fields("Sitecode")%>><%=.fields("Sitecode")%></option>

		<%

		.movenext

		loop

		%>

Open in new window

0
Comment
Question by:gr33d
  • 5
  • 2
9 Comments
 
LVL 13

Expert Comment

by:samic400
ID: 20426575
Would it be OK if I offered an AJAX solution that uses ASP?
0
 
LVL 1

Author Comment

by:gr33d
ID: 20426937
I'm even more of a newbie to AJAX than to ASP and ADO, but if it works the way I'd like it, then absolutely!
0
 
LVL 13

Accepted Solution

by:
samic400 earned 500 total points
ID: 20427072
ok - here it goes - your first page should look like this:

<html>
<head>
<script type="text/javascript">
   var http_request = false;
      
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
       http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
       http_request = new ActiveXObject("Microsoft.XMLHTTP");
      }

    function getAJAXdata(dataSource, divID) {
                  
       if(http_request) {
         var obj = document.getElementById(divID);
         http_request.open("GET", dataSource);
        
         http_request.onreadystatechange = function() {
             if (http_request.readyState == 4 && http_request.status == 200) {
                obj.innerHTML = http_request.responseText;
            }
        }
             
       http_request.send(null);
      
        }
      
      }
</script>
</head>
<body>
<form name='form1' action='submitform.asp'>
<%
set con = server.createObject("adodb.connection")
set rs = server.createObject("adodb.recordset")
con.open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db.mdb")
rs.open "select Sitecode from addresses",con
with rs
%>
<select name='sitecode' onchange="getAJAXdata('ajax.asp?id=' + document.form1.sitecode.options[document.form1.sitecode.selectedIndex].value,'targetDiv');">
<%
 do until .eof
%>
<option value = <%=.fields("Sitecode")%>><%=.fields("Sitecode")%></option>
<%
.movenext
loop
%>
<br>
<div id='targetDiv'>
</div>
<br><br>
<input type='submit' value='submit data'>
</form>
</body>
</html>
0
 
LVL 13

Expert Comment

by:samic400
ID: 20427096
your second page - which i called ajax.asp - gets called when a drop down selection from 'sitecode' gets changed. the contents between the <div id='targetDiv'> and </div> is what gets updated. this would be your location drop down.

this is the ajax.asp page

<%
set con = server.createObject("adodb.connection")
set rs = server.createObject("adodb.recordset")
con.open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db.mdb")
rs.open "select location from addresses where sitecode=" & request.querystring("id"),con
with rs
response.write("<select name = 'location'>")
 do until .eof
%>
<option value = <%=.fields("location")%>><%=.fields("location")%></option>
<%
.movenext
loop
%>
</select>


0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 13

Expert Comment

by:samic400
ID: 20427105
the last page would be your "action" page from your <form> tag - which I called submitform which you would do whatever needed to be done with the data.

Hope this helps!
0
 
LVL 1

Author Comment

by:gr33d
ID: 20492691
On the last page (submitform.asp), is there a way to keep the page from refreshing. On submit, I just want to calculate and overlay the route on the map div item. Wouldn't the submitform.asp redirect to another page?

Can you recommend any AJAX tutorials available for free on the web?

Thanks in advance, and I'll start testing this asap!
0
 
LVL 13

Expert Comment

by:samic400
ID: 20493885
This is what I think I used to start learning AJAX - http://www.w3schools.com/ajax/

I believe the book that I use the most as a reference is "AJAX for Dummies."
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21133386
Forced accept.

Computer101
EE Admin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now