View Full Version : ASP & Java script - Rollover Photo Change

08-17-2007, 12:55 PM
Help, I am a bit stuck with a problem.

I want to achieve the following.

We have a website written in ASP. Many of the pages are generated out of a database. These pages contain, amongst other information the names of images to be displayed (up to 6 per page).

The images are to be displayed as thumbnails with one of the also displayed as a larger image. When we rollover the thumbs we want the larger image to change accordingly.

How do we use the image names that are read out of the database with the ASP code to work with javascript functions? :confused: :confused:

08-17-2007, 03:29 PM
You can mix JS and ASP together easily, as long as you follow 2 simple rules:

1) If you know your JS before hand, make sure that the variables are in JS and the data is ASP.


<script language="javascript">
function testMe() {
var test = '<%= session("var_from_db") %>';

2) If you don't know how your ASP will interact with JS, then use ASP to write the JS for you.


<% response.write("<script language=""javascript"">" & vbCrLf)
response.write("function testMe() {" & vbCrLf)
for each i in session.contents
response.write(" var " & i & " = '" & session(i) & "';" & vbCrLf)
response.write("</script>" & vbCrLf) %>

This is just example code and won't work, but it does give you an example of how you can populate JS with ASP variables.

08-17-2007, 03:29 PM
I have an idea, but post the code for the large image and the thumbnails or all of the code if you want.