toplisek
01-07-2006, 06:14 PM
I have code Java Script that it does not show images with local up directory
images. What to change in var baser = "" that script will work and show main images1, mainimage2...mainimage4.gif when user goes over image 1 or image 2...to image4.gif? there is also test field that links work.... :)
Code is:
<script type="text/javascript">
function switchGIF(ID)
{
var i;
var baser = ""
var myarray=new Array('image1.gif','mainimage1a.gif','image2.gif','mainimage2a.gif','image3.gif','mainimage3a.gif','image4.gif','mainimage4a.gif');
for(i=0;i<myarray.length;i++)
{
if ((document.getElementById(ID).src==(baser + myarray[i])) && ((i%2)==0))
{
document.getElementById(ID).src=myarray[i+1];
i= myarray.length;
}
else if ((document.getElementById(ID).src==(baser + myarray[i])) && ((i%2)==1))
{
document.getElementById(ID).src=myarray[i-1];
i= myarray.length;
}
}
document.getElementById('one').value = document.getElementById(ID).src;
}
</script>
and in body:
<img name="img1" id="img1" src="mainimage1a.gif" onmouseover="switchGIF(this.id)" onmouseout="switchGIF(this.id)">
<img name="img2" id="img2" src="mainimage2a.gif" onmouseover="switchGIF(this.id)" onmouseout="switchGIF(this.id)">
<img name="img3" id="img3" src="mainimage3a.gif" onmouseover="switchGIF(this.id)" onmouseout="switchGIF(this.id)">
<img name="img4" id="img4" src="mainimage4a.gif" onmouseover="switchGIF(this.id)" onmouseout="switchGIF(this.id)">
<input type="text" id="one" size="300">
images. What to change in var baser = "" that script will work and show main images1, mainimage2...mainimage4.gif when user goes over image 1 or image 2...to image4.gif? there is also test field that links work.... :)
Code is:
<script type="text/javascript">
function switchGIF(ID)
{
var i;
var baser = ""
var myarray=new Array('image1.gif','mainimage1a.gif','image2.gif','mainimage2a.gif','image3.gif','mainimage3a.gif','image4.gif','mainimage4a.gif');
for(i=0;i<myarray.length;i++)
{
if ((document.getElementById(ID).src==(baser + myarray[i])) && ((i%2)==0))
{
document.getElementById(ID).src=myarray[i+1];
i= myarray.length;
}
else if ((document.getElementById(ID).src==(baser + myarray[i])) && ((i%2)==1))
{
document.getElementById(ID).src=myarray[i-1];
i= myarray.length;
}
}
document.getElementById('one').value = document.getElementById(ID).src;
}
</script>
and in body:
<img name="img1" id="img1" src="mainimage1a.gif" onmouseover="switchGIF(this.id)" onmouseout="switchGIF(this.id)">
<img name="img2" id="img2" src="mainimage2a.gif" onmouseover="switchGIF(this.id)" onmouseout="switchGIF(this.id)">
<img name="img3" id="img3" src="mainimage3a.gif" onmouseover="switchGIF(this.id)" onmouseout="switchGIF(this.id)">
<img name="img4" id="img4" src="mainimage4a.gif" onmouseover="switchGIF(this.id)" onmouseout="switchGIF(this.id)">
<input type="text" id="one" size="300">