Jump to content

Rollover images in Javascript


houssam_ballout

Recommended Posts

Hello all, I am customizing a script that is used on rollover for images, but it wont work , can u help me with it? (there is no problem with images)The code is:

<HTML><HEAD><TITLE>Multiple Rollovers</TITLE><script LANGUAGE = "JavaScript"><!--if (document.images) {img1On = new Image();img1On.src = "1.jpg"; // Active Imagesimg2On = new Image();img20n.src = "2.jpg";img1Off = new Image();img1Off.src = "2.jpg"; // Inactive Imagesimg2Off = new Image();img20ff.src = "1.jpg";//img1ad = new Image(); //img1ad.src = "1.jpg"; // Information Images//img2ad = new Image();//img2ad.src = "2.jpg";}// Function to 'activate' images.function imgOn(imgName) {if (document.images) {document[imgName].src = eval(imgName + "on.src");//document["holder"].src = eval(imgName + "ad.src");}} // Function to 'deactivate' images. function imgOff(imgName) {if (document.images) {document[imgName].src = eval(imgName + "off.src");//document["holder"].src = "1.jpg";}}// --></SCRIPT> </HEAD> <BODY BGCOLOR = "#FFFFFF"><!-- 1st Rollover --> <a HREF="jukebox.html" onMouseOver = "imgOn('imgl')" onMouseOut = "imgOff('img1')"> <IMG NAME= "imgl" BORDER="0" HEIGHT="24" WIDTH="100" SRC="1.jpg"></A><!-- 2nd Rollover --> <a HREF="videos.html" onMouseOver = "imgOn('img2')" onMouseOut = "imgOff('img2')"><IMG NAME= "img2" BORDER="0" HEIGHT="24" WIDTH="100" SRC="2.jpg"></A></BODY> </HTML>

Link to comment
Share on other sites

Try this instead:

<HTML><HEAD><TITLE>Multiple Rollovers</TITLE><script LANGUAGE = "JavaScript"><!--if (document.images) {img1On = new Image();img1On.src = "1.jpg"; // Active Imagesimg2On = new Image();img20n.src = "2.jpg";img1Off = new Image();img1Off.src = "2.jpg"; // Inactive Imagesimg2Off = new Image();img20ff.src = "1.jpg";//img1ad = new Image();//img1ad.src = "1.jpg"; // Information Images//img2ad = new Image();//img2ad.src = "2.jpg";}// Function to 'activate' images.function imgOn(imgName) {if (document.images) {document.getElementById(imgName).src = eval(imgName + "on.src");//document["holder"].src = eval(imgName + "ad.src");}}// Function to 'deactivate' images.function imgOff(imgName) {if (document.images) {document.getElementById(imgName).src = eval(imgName + "off.src");//document["holder"].src = "1.jpg";}}// --></SCRIPT></HEAD><BODY BGCOLOR = "#FFFFFF"><!-- 1st Rollover --><a HREF="jukebox.html" onMouseOver = "imgOn('imgl')" onMouseOut = "imgOff('img1')"><IMG ID= "imgl" BORDER="0" HEIGHT="24" WIDTH="100" SRC="1.jpg"></A><!-- 2nd Rollover --><a HREF="videos.html" onMouseOver = "imgOn('img2')" onMouseOut = "imgOff('img2')"><IMG ID= "img2" BORDER="0" HEIGHT="24" WIDTH="100" SRC="2.jpg"></A></BODY></HTML>

I replaced your names with IDs and changed the way you fetch the elements to document.getElementById(). It should now work. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...