Web Hosting Talk







View Full Version : Help with javascript


PeeDi
07-28-2004, 09:15 AM
hey guys

I am having trouble with a javascript for rollovers. I am using a tutorial which is HERE (http://www.pageresource.com/jscript/jhover.htm)

I was wondering if anyone would be kind enough to show me a full example of the script completed??

I am just finding hard to follow this tut, I have got most of it just missing a few bits.

Kind regards

PostD

pacres
07-28-2004, 09:38 AM
This is the completed script.
Add this to the head of your document.

<SCRIPT language="JavaScript">
<!--

if (document.images)
{
pic1on= new Image(100,25);
pic1on.src="../images/shoes2.gif";
pic2on= new Image(100,25);
pic2on.src="../images/story2.gif";

pic1off= new Image(100,25);
pic1off.src="../images/shoes1.gif";
pic2off= new Image(100,25);
pic2off.src="../images/story1.gif";
}

function lightup(imgName)
{
if (document.images)
{
imgOn=eval(imgName + "on.src");
document[imgName].src= imgOn;
}
}

function turnoff(imgName)
{
if (document.images)
{
imgOff=eval(imgName + "off.src");
document[imgName].src= imgOff;
}
}

//-->
</SCRIPT>


Then in the body of your html where you wish the mouse over to appear place this.

<A HREF="index.html" onMouseover="lightup('pic1')" onMouseout="turnoff('pic1')">
<IMG SRC="../images/shoes1.gif" name="pic1" width="100" height="25" border="0"></A>

PeeDi
07-28-2004, 09:45 AM
Thats not it completed, thats just how it is on the tutorial. I need a full working example with everything completed

e.g. you haven't filled in the (imgName) sections or this section

imgOn=eval(imgName + "on.src");
document[imgName].src= imgOn;

all you have done is posted a rough guide, which I have been trying to figure out but not having much luck with.

If you could post a full example that would be great, but thanks anyway:)

Kind regards

PostD

pacres
07-28-2004, 09:53 AM
you just need to substitite your file names with the ones in the tutorial.

pic1on.src="../images/shoes2.gif";

replace ../images/shoes2.gif with your image
eg - ./images/yourpic.jpg

You might be having trouble with the path. Try using ./ instead of ../

I'm not sure what part you are having trouble with, could you let me know what problem you get when you try to run the code.