Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Classic dropdown question

Status
Not open for further replies.

mazdaman

Programmer
Oct 17, 2003
55
GB
How do i make a dropdown box populated from a MS Access database.Ive searched the faqs etc but have not found an answer i can work with.

The first dropdown would show a straight list from a table

'Select CourseID, from Coureslist',

Making a selection in this box would then get the details from the following query

'SELECT Applications.*, Courselist.*, Coursetitles.*
FROM Coursetitles RIGHT JOIN (Courselist RIGHT JOIN Applications ON Courselist.CourseID = Applications.CourseID) ON Coursetitles.CourseCode = Courselist.CourseCode
WHERE Courselist.CourseID ='CID'

Courselist = course ID numbers
Coursetitles = titles of the course, has a unique ID containd in the table 'Courselist'
Applications = provids further title information linked to other table (ignore)

Thanks for your help :)

 

As you've not said whether you want client-side or server-side JavaScript, I'll assume you are writing server-side JavaScript for ASP, as you also have DB calls.

There are two main ways of doing it. One with client-side JavaScript (which is pointless if you have server-side technology available, as you would only be alienating some people who don't have JS. I will not be going down this route). The other is to build up the HTML server-side, and simply output it to the page.

Something like this, assuming your returned recordset is in a variable called "rs", and your fields are called "optValue" and "optText" respectively:

Code:
<%@ language=Javascript%>
<%
	// Do database query stuff here. Return recordset in a variable called "rs".

	var selOpts = '';
	while (!rs.EOF)
	{
		selOpts += '<option value="' + rs('optValue').value + '">' + rs('optText').value + '</option>\n';
		rs.MoveNext();
	}

	var selHTML = '<select>\n' + selOpts + '</select>\n';
%>
<html>
<head></head>

<body>
	<form>
		<%=selHTML%>
	</form>
</body>
</html>

Hope this helps,
Dan


The answers you get are only as good as the information you give!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top