?
Solved

Populate subsequent combo boxes using recordset

Posted on 2007-12-05
9
Medium Priority
?
1,105 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 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

649 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