[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Populate subsequent combo boxes using recordset

Posted on 2007-12-05
9
Medium Priority
?
1,107 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
8 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 2000 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
Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

 
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
 
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

834 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