PDA

View Full Version : The dreadful, awful, "same old" dilemma: help to run 2 scripts on 1 page...



PattyKake
04-19-2005, 09:02 PM
Live Date
http://dynamicdrive.com/dynamicindex6/clock3.htm

Fade-In Slideshow
http://www.dynamicdrive.com/dynamicindex14/fadeinslideshow.htm

My web page is currently running the "fade-in slideshow" script. I would like to add "live date".

I've read "Adding more than one JavaScript to a page" and onward reading "One event handler, many actions" but have failed in my efforts to run both at the same time.

How do I delete "window.onload=startit" from the ending "if" statement of the fade-in slideshow script:

if (ie4||dom)
window.onload=startit
else
setInterval("rotateimage()",pause)

</script>

so that "startit" can be included it as part of the body tag:

body onload="startit();goforit()"

please help to save a damsel in distress,
PattyKake

jscheuer1
04-20-2005, 04:20 AM
if ((!ie4)&&(!dom))
setInterval("rotateimage()",pause)


body onload="goforit();if (ie4||dom){startit()}"

PattyKake
04-20-2005, 12:50 PM
It was wonderful to see a solution waiting for me this morning. Thanks so much. I tried it first thing, but unforturnately I still can't get the date script to run. Logic tells me there's a conflict with "getting" the seconds????? The slideshow pauses every 3 seconds. I don't know.....I'm fishing here...

Is there anything else that can be done??

PattyKake

jscheuer1
04-20-2005, 03:33 PM
Well, I tested this after I posted it and it worked here. So, I may need to see your work. Three things, what browser are you using? I tested in NS7.2, IE6 and FF1.0.3. All fine. Did you, when copying my body tag from my post, remember to enclose it in the < > braces? Have you, by chance, left the '<span id="clock"></span>' out of your page? Other than that, I can paste in my work if that will be of any further help:
<html>
<head>
<title>Timer/Fade Demo</title>
</head>
<body onload="goforit();if (ie4||dom){startit()}">
<script language="JavaScript1.2" type="text/javascript">

/***********************************************
* Fade-in image slideshow script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var slideshow_width='140px' //SET IMAGE WIDTH
var slideshow_height='225px' //SET IMAGE HEIGHT
var pause=3000 //SET PAUSE BETWEEN SLIDE (3000=3 seconds)

var fadeimages=new Array()
//SET IMAGE PATHS. Extend or contract array as needed
fadeimages[0]="photo1.jpg"
fadeimages[1]="photo2.jpg"
fadeimages[2]="photo3.jpg"

////NO need to edit beyond here/////////////

var preloadedimages=new Array()
for (p=0;p<fadeimages.length;p++){
preloadedimages[p]=new Image()
preloadedimages[p].src=fadeimages[p]
}

var ie4=document.all
var dom=document.getElementById

if (ie4||dom)
document.write('<div style="position:relative;width:'+slideshow_width+';height:'+slideshow_height+';overflow:hidden"><div id="canvas0" style="position:absolute;width:'+slideshow_width+';height:'+slideshow_height+';top:0;left:0;filter:alpha(opacity=10);-moz-opacity:10"></div><div id="canvas1" style="position:absolute;width:'+slideshow_width+';height:'+slideshow_height+';top:0;left:0;filter:alpha(opacity=10);-moz-opacity:10;visibility: hidden"></div></div>')
else
document.write('<img name="defaultslide" src="'+fadeimages[0]+'">')

var curpos=10
var degree=10
var curcanvas="canvas0"
var curimageindex=0
var nextimageindex=1


function fadepic(){
if (curpos<100){
curpos+=10
if (tempobj.filters)
tempobj.filters.alpha.opacity=curpos
else if (tempobj.style.MozOpacity)
tempobj.style.MozOpacity=curpos/101
}
else{
clearInterval(dropslide)
nextcanvas=(curcanvas=="canvas0")? "canvas0" : "canvas1"
tempobj=ie4? eval("document.all."+nextcanvas) : document.getElementById(nextcanvas)
tempobj.innerHTML='<img src="'+fadeimages[nextimageindex]+'">'
nextimageindex=(nextimageindex<fadeimages.length-1)? nextimageindex+1 : 0
var tempobj2=ie4? eval("document.all."+nextcanvas) : document.getElementById(nextcanvas)
tempobj2.style.visibility="hidden"
setTimeout("rotateimage()",pause)
}
}

function rotateimage(){
if (ie4||dom){
resetit(curcanvas)
var crossobj=tempobj=ie4? eval("document.all."+curcanvas) : document.getElementById(curcanvas)
crossobj.style.zIndex++
tempobj.style.visibility="visible"
var temp='setInterval("fadepic()",50)'
dropslide=eval(temp)
curcanvas=(curcanvas=="canvas0")? "canvas1" : "canvas0"
}
else
document.images.defaultslide.src=fadeimages[curimageindex]
curimageindex=(curimageindex<fadeimages.length-1)? curimageindex+1 : 0
}

function resetit(what){
curpos=10
var crossobj=ie4? eval("document.all."+what) : document.getElementById(what)
if (crossobj.filters)
crossobj.filters.alpha.opacity=curpos
else if (crossobj.style.MozOpacity)
crossobj.style.MozOpacity=curpos/101
}

function startit(){
var crossobj=ie4? eval("document.all."+curcanvas) : document.getElementById(curcanvas)
crossobj.innerHTML='<img src="'+fadeimages[curimageindex]+'">'
rotateimage()
}

if ((!ie4)&&(!dom))
setInterval("rotateimage()",pause)

</script>

<p align="center"><font face="Arial" size="-2">Free DHTML scripts provided by<br>
<a href="http://www.dynamicdrive.com">Dynamic Drive</a></font></p>

<script>

/*
Live Date Script-
Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions, 100's more DHTML scripts, and Terms Of Use,
visit http://www.dynamicdrive.com
*/


var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")

function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12){
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
//change font size here
var cdate="<small><font color='000000' face='Arial'><b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn
+"</b></font></small>"
if (document.all)
document.all.clock.innerHTML=cdate
else if (document.getElementById)
document.getElementById("clock").innerHTML=cdate
else
document.write(cdate)
}
if (!document.all&&!document.getElementById)
getthedate()
function goforit(){
if (document.all||document.getElementById)
setInterval("getthedate()",1000)
}

</script>
<span id="clock"></span>
</body>
</html>

PattyKake
04-20-2005, 05:57 PM
Apologies first....I did eliminate '<span id="clock"></span>' through processes of different trials. I've corrected that and my clock appeared!!

Here is the result of your much needed and appreciated help...
http://tsicompliance.com/default.htm

Thanks, 'jscheuer1' !!!!!!!

PattyKake

jscheuer1
04-20-2005, 07:04 PM
That's OK, happens all the time. Very nice looking site and we all could use cleaner air!