How to populate a drop down menu from a database without refreshing the page

Posted on 2008-10-22
Last Modified: 2010-04-21
I have form on my page and based on what the user chooses from the first drop down menu, I want the next drop down menu to populate with values from a database.  I've attached a copy of the code and the asp function I'm trying to call.

When I select my survey project from the 1st drop down, I get the alert -> There was a problem while using XMLHTTP: Internal Server Error.

The getsurvey.asp code appears to be working and I've included the output from this function when I test the program in my browser.

Can someone please help me figure out what I'm doing wrong?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">



<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>My title</title>

<SCRIPT TYPE="text/javascript">



function getSurveys(dbPath)


   var strURL="getsurvey.asp?dbpath=" + dbPath;

   var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

   if (xmlhttp)


      xmlhttp.onreadystatechange = function()


         if (xmlhttp.readyState == 4)


	   // only if "OK"

	   if (xmlhttp.status == 200)



	   } else {

   	      alert("There was a problem while using XMLHTTP:\n" + xmlhttp.statusText);



      }"GET", strURL, true);


   } else {

      alert("There was a problem creating the xmlhttp object");







<table width="100%" border="0" cellpadding="0" cellspacing="5">


    <td align="left" valign="top">Project Survey:</td>

    <td align="left" valign="top">

      <select name="Projects" onChange="getSurveys(this.value)">

        <option>Select Project Survey</option>

        <option value="mypath\mydbname.mdb">Survey Project 1</option>





    <td align="left" valign="top">Program Survey:</td>

    <td align="left" valign="top">

      <p id="surveydiv">

        <select name="survey"><option>Select Project Survey First</option></select>











<% Option Explicit %>

<!--#include file="functions.asp"-->


Dim MyConn, ConnStr, rs, dbPath, dbName

dbName = "\" & Right(Request.QueryString("dbpath"), Len(Request.QueryString("dbpath")) - InStrRev(Request.QueryString("dbpath"), "\"))

dbPath = Left(Request.QueryString("dbpath"), Len(Request.QueryString("dbpath")) - Len(dbName))

Call OpenDatabase(MyConn, adModeShareDenyNone, dbPath, dbName)

ConnStr = "SELECT presenterid, program FROM Presenter;"

set rs = MyConn.Execute(ConnStr)


<select name="surveys">

	<option>Select Program Survey</option>

	<% do while rs.EOF = false %>

	<option value=<%=rs("presenterid")%>><%=rs("program")%></option>

	<%		rs.MoveNext

		loop %>


<% Call Database_Close(MyConn) %>


getsurveys.asp output


<select name="surveys">

	<option>Select Program Survey</option>


	<option value=37>Program 1</option> -->


	<option value=33>Program 2</option>


	<option value=34>Program 3</option>


	<option value=35>Program 4</option>	

	<option value=36>Program 5</option>	


Open in new window

Question by:dyarosh
  • 2

Accepted Solution

ASPSQLServerCOM earned 500 total points
ID: 22780621
first try this example
The reference site W3Schools has a good section on AJAX

There is also a good explanation on what AJAX is at
LVL 19

Expert Comment

by:Albert Van Halen
ID: 22780683
Perhaps a typo ?? Your page is called getsurveys.asp, yet you make a request to getsurvey.asp.

Author Closing Comment

ID: 31508848
Thanks for the help.  Your solution worked.  Also, the typo was in my posting where I labeled the program name.
LVL 19

Expert Comment

by:Albert Van Halen
ID: 22787034
Hi dyarosh, like to hear what your solution was for your problem.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now