Solved

Populate subsequent combo boxes using recordset

Posted on 2007-12-05
9
1,103 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Webinar: MongoDB® Index Types

Join Percona’s Senior Technical Services Engineer, Adamo Tonete as he presents “MongoDB Index Types, How, When and Where Should They be Used?” on Wednesday, July 12, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7).

 
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

688 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