Link to home
Start Free TrialLog in
Avatar of gr33d
gr33d

asked on

Populate subsequent combo boxes using recordset

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

Avatar of Bob Butcher
Bob Butcher
Flag of United States of America image

Would it be OK if I offered an AJAX solution that uses ASP?
Avatar of gr33d
gr33d

ASKER

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!
ASKER CERTIFIED SOLUTION
Avatar of Bob Butcher
Bob Butcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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>


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!
Avatar of gr33d

ASKER

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!
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."
Forced accept.

Computer101
EE Admin