AJax, jQuery and ASP (Classic)

Posted on 2010-09-16
Last Modified: 2012-06-27
I have a calendar page I wrote in ASP.  

When a person clicks an event link, it reloads the same page with an eventID so that at the bottom of the page the event details appear.

I would like to change this to have the event details pop up in modal box without refreshing the page.  So I figure use jQuery and AJAX, two technologies I dont' know enough about...

I’m not sure if I’m in the neighborhood with my thought process, and my code isn't working, so I thought I'd share what I did in hopes that I could get some help...

1.Generate the link in ASP:  DateText = DateText & "<a class='littleLink' href='#' onclick='getEvent(" & objrs("eidNumber") & ")' name='modal'>"&objrs("eTitleOfEvent")&"</a>"

2.The Javascript function “getEvent” sends the event ID to a process page: calproc.asp (I've attached the code below)

3. calproc.asp writes the response.

Here's where I get fuzzy...

Since the name of the link asp generates is "modal", I assume that clicking it should trigger the jQuery.  Since the javascript fires, I assume that the response.write function will display on top of the modal box.

But ofcourse when you assume you make an a... well you get the point.

Something worth noting.  The html for the modal box is:

<div id="boxes">
      <div id="dialog" class="window">
          I want my data here.
      <a href="#"class="close"/>Close it</a>
        <div id="mask"></div>

I dont' have this code in my page, I have the calproc.asp page generate it.  This is probably part of the problem, but I wasn't sure how else to get the "response.write" text into the area where the data should go.

I hope this makes sense.

thanks for your help!
jQuery code:

<script type="text/javascript" src=""></script>


$(document).ready(function() {	

	//select all the a tag with name equal to modal

	$('a[name=modal]').click(function(e) {

		//Cancel the link behavior



		//Get the A tag

		var id = $(this).attr('href');


		//Get the screen height and width

		var maskHeight = $(document).height();

		var maskWidth = $(window).width();


		//Set heigth and width to mask to fill up the whole screen



		//transition effect		




		//Get the window height and width

		var winH = $(window).height();

		var winW = $(window).width();


		//Set the popup window to center

		$(id).css('top',  winH/2-$(id).height()/2);

		$(id).css('left', winW/2-$(id).width()/2);


		//transition effect





	//if close button is clicked

	$('.window .close').click(function (e) {

		//Cancel the link behavior







	//if mask is clicked

	$('#mask').click(function () {







Javascript Code:

<script type="text/javascript">

function getEvent(did)


if (did.length==0)





if (window.XMLHttpRequest)

  {// code for IE7+, Firefox, Chrome, Opera, Safari

  xmlhttp=new XMLHttpRequest();



  {// code for IE6, IE5

  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");




  if (xmlhttp.readyState==4 && xmlhttp.status==200)








calproc.asp code:

eid = Request("did")

if isNumeric(eid) = false then

	Response.Write("Nothing found.")


	if eid <> "" then

		sql = "Select * from myTable where eId = " & eid

		set objrs = objconn.execute(sql)

		if objrs.eof and objrs.bof then



			EventName = objrs("eTitle")

			dEventDate = objrs("eDate")

			EventDesc = objrs("eLongDesc")

			EventLink = objrs("eLink")

			EventImage = objrs("eImage")

			if isNull(EventImage) = True then

				EventImage = ""

			End if

		end if

		Response.Write("<div id='boxes'>")

		Response.Write("<div id='dialog' class='window'>")


		Response.Write("<table border='0' cellpadding='0' cellspacing='0' width='100%' class='ventinfo'>")

		Response.Write("<tr><td class='eventTitle' colspan="2">" & EventName & " - " & dEventDate & "</td>")

		Response.Write("</tr><tr><td colspan='2' height='10px'></td></tr><tr>")

		if EventImage = "" then 



        response.Write("<td><img src='" & EventImage & "' width='100px'/></td>")

		end if

        Response.Write("<td style='padding-left:5px;'>" & EventDesc & "</td></tr><tr><td colspan='2' height='10px'></td> </tr><tr><td></td>")

		Response.Write("<td style='padding-bottom:4px; padding-left:5px;'><a href='" & EventLink & "' target='_blank' class='eventLink'>Click here for more information!</a></td></tr></table>")


		Response.Write("<div id='mask'></div>")

	End if

end if

Open in new window

Question by:slightlyoff

Accepted Solution

rbgCODE earned 500 total points
ID: 33696559
Really the best way to do this is to have an external page like


that does all your database work, then when someone calls the javascript you can just have it pull back the code you got from functions.asp and then display it within a pop-up window.  

Your javascript would need to first have a call out, then look for a response back..

function ajaxGrab(writeDiv,urlBuilder){
 var nurl = "a_JAX.asp?" + urlBuilder + "&d=" + writeDiv + "";
 if (document.getElementById(uLayer).innerHTML != "" && uLayer != "RecentHistory"){
   var styleObject = getStyleObject(uLayer);
 //alert(nurl + " to " + uLayer);
 xmlHttp=GetXmlHttpObject(stateChanged);"GET", nurl , true);  

function stateChanged(){  
 if (uLayer != ""){
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
   var styleObject = getStyleObject(uLayer);
 }else{alert("No divName passed?");}

function ajaxHide(hideDiv){
var styleObject = getStyleObject(hideDiv);

function ajaxShow(showDiv){
 var checkStyle = "none";
 var noStyle = "";
 var styleObject = getStyleObject(showDiv);
 if (styleObject.display == checkStyle){styleObject.display=noStyle;}

Author Closing Comment

ID: 33737745
Thank you, I appreciate your help!

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
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…

758 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