Solved

Populate subsequent combo boxes using recordset

Posted on 2007-12-05
9
1,095 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now