View Full Version : How to have this work a few times on one page....

07-16-2004, 02:19 AM
I've been Googling like crazy.. :confused: .. I really :o really would like to have this javascript appear a few times on my site.. :) .. It's one of those picture slideshow things.. :thumbsup: .. Hmmmmmm. I don't know how :mad: . I sincerely thank you for the solution :) , or direction to the solution :) .... Here it is:

<p align="center"><input type="button" name="btnPrev" value="&lt;&lt;---" onclick="Prev();">&nbsp; <span id="_Ath_Img_X"></span> &nbsp;of&nbsp;<span id="_Ath_Img_N"></span> &nbsp;<input type="button" name="btnNext" value="---&gt;&gt;" onclick="Next();"></p>
<span id="_Ath_FileName"><font color="#666666"><small></span><p align="center"><img name="_Ath_Slide" onload="OnImgLoad()" height="125" width="125"></p></p><p align="center"><script language="JavaScript1.2" event="onload" for="window">main();</script><script language="JavaScript1.2">
g_fPlayMode = 0;g_iimg = 0;g_imax = 0;g_ImageTable = new Array();function ChangeImage(fFwd){if (fFwd){if (++g_iimg==g_imax)g_iimg=0;}else{if (g_iimg==0)g_iimg=g_imax; g_iimg--;}Update();}function Update(){document.all._Ath_Slide.src = g_ImageTable[g_iimg][0]; document.all._Ath_FileName.innerHTML = g_ImageTable[g_iimg][1];document.all._Ath_Img_X.innerHTML = g_iimg + 1;document.all._Ath_Img_N.innerHTML = g_imax;}function Play(){g_fPlayMode = !g_fPlayMode;if (g_fPlayMode){btnPrev.disabled = btnNext.disabled = true;Next();}else {btnPrev.disabled = btnNext.disabled = false;}} function OnImgLoad(){if (g_fPlayMode)window.setTimeout("Tick()", g_dwTimeOutSec*1000);}function Tick() {if (g_fPlayMode)Next();} function Prev(){ChangeImage(false);}function Next(){ChangeImage(true);}function main(){Update();}

g_ImageTable[g_imax++] = new Array ("http://www.picture-url.com/.jpg", "<a href='http'>description</a>");
g_ImageTable[g_imax++] = new Array ("http://www.picture-url.com/.jpg", "<a href='http'>description</a>");
g_ImageTable[g_imax++] = new Array ("http://www.picture-url.com/.jpg", "<a href='http'>description</a>");


Best wishes... :thumbsup:

07-16-2004, 03:40 AM
Use an OO-based Slideshow script like this (http://peterbailey.net/dhtml/oo_slideshow.htm). The source can be found here (http://peterbailey.net/dhtml/showsrc.php?file=slideshow).

07-16-2004, 06:39 AM
Is there no other way?:o
I found this as a possible soloution(( thanx to javascriptkit.com)):

The way to go about solving this conflict is simple, though not quite the same to explain. Essentially, what you want is to end up with only ONE delta for both scripts, with that delta calling the two scripts. Let's list some possible scenarios now, and their resolutions:

SCRIPT 1: <body onload="dothis()">
SCRIPT 2: <body onload="dothat()">
RESOLUTION: <body onload="dothis();dothat()">

SCRIPT 1: <body onload="dothis()">
SCRIPT 2: window.onload=dothat()
RESOLUTION: <body onload="dothis();dothat()">

SCRIPT 1: window.onload=dothis
SCRIPT 2: window.onload=dothat
RESOLUTION: <body onload="dothis();dothat()">

As you can see, regardless of whether the two scripts contain "delta" or "beta", the resolution is the same- remove BOTH lines, and call the scripts directly within the <body> tag, each separated by a semicolon. If you wish to combine three scripts, the procedure is the exact same.

By using the above technique, both scripts are called and executed, as opposed to just one- or neither. In other words, conflict avoided! Check out http://www.javascriptkit.com/javatutors/eventaction4.shtml for some additional information on resolving script conflicts. Good luck!
but :confused: after changing this-that woohoo..grr :mad: ..I this no figure out..
I really like this little slideshow thing---took a while to customize it and make it perfect---I'll be updating a lot, so it's a good one for it :thumbsup: ..
I don't know much about it... Any suggestions, or is the above not likely to happen...
Thanx.. :)

Willy Duitt
07-16-2004, 01:57 PM
Your script was not written to be used multiple times on a page. Every variable used within the script is in the global scope and if more than one instance of the script is running on a page the multiple instances of these global variables will conflict with eachother.

If you insist on using multiple instances of this script you will need to change all the variable and function names so that each is unique along with moving the multiple function calls to the body onload handler as you described above...

I concur with Glenn and also suggest that you look for another script which was written to be object orientated....


07-16-2004, 05:09 PM
Thanx for the direction :thumbsup:
--Spent a couple hours trying to change everything..., but did not work;
--Tried to figure out how the suggested OO-based one works..., no luck yet, but will continue until I've got it.......

!!!!!!! :) Thanx !!!!!!!!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum