PDA

View Full Version : Simple MM_Swap Image problem -help!



dannyflint
Jul 19th, 2005, 03:15 PM
Hi, I am neewbie so forgive if this is very simple.

This is a snippet of code on one of my pages:

MM_swapImage('pricepic','','images/price_25.gif',0) } - which works fine.

However, I have this piece of code repeated many times on my page and therefore i would like the image path ( 'images/price_25.gif') to be defined in a variable, so that in the future I just have to change the variable at the top of the page, and not over and over.

I want the variable to go here --------V
MM_swapImage('pricepic','','xxxxxxxxxxxxxxxxxxxxxxxxxx',0)


CAN SOMEONE HELP ME!!

Thanks for your time

Danny

nikkiH
Jul 19th, 2005, 03:37 PM
var imgPath = "images/price_25.gif"
MM_swapImage('pricepic','',imgPath,0)

vwphillips
Jul 19th, 2005, 06:15 PM
if your mouse over and out images are in the same directory this may be of interest




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
function swapImage(imgobj,trigobj,img){
if (typeof(imgobj)!='object'){
imgobj=document.getElementById(imgobj);
}
if (!imgobj.outimg){
imgobj.outimg=imgobj.src;
}
imgobj.src=imgobj.src.substring(0,(imgobj.src.lastIndexOf('/')+1))+img
trigobj.tar=imgobj;
trigobj.onmouseout=function(){ this.tar.src=this.tar.outimg; }
}

//-->
</script></head>

<body>
<img id="MyImg1" src="http://www.vicsjavascripts.org.uk/StdImages/Zero.gif" onmouseover="swapImage(this,this,'One.gif',0);" width=100 height="20" >
<br>
<a href="#" onmouseover="swapImage('MyImg1',this,'Two.gif',0);" >Two</a><br>
<br>
<a href="#" onmouseover="swapImage('MyImg1',this,'Three.gif',0);" >Three</a><br>
<br>
<a href="#" onmouseover="swapImage('MyImg1',this,'Four.gif',0);" >Four</a><br>
<br>
<a href="#" onmouseover="swapImage('MyImg1',this,'Five.gif',0);" >Five</a><br>

</form>


</body>

</html>



the previous suggestion of

var imgPath = "images/price_25.gif"
MM_swapImage('pricepic','',imgPath,0)


could be

var imgPath1 = 'images/';

MM_swapImage('pricepic','',imgPath1+price_25.gif',0)

so the imgPath can be used for numerous images
and of cause you can have

var imgPath2='moreimages/'; for other images as applicable