Forum Moderators: phranque

Message Too Old, No Replies

multiple functions with one onload?

         

kslnor

5:53 pm on Mar 5, 2006 (gmt 0)

10+ Year Member



I can't seem to get multiple functions to work with the onload handler. Basically, I have a slideshow script and navigation fly-out script. Here is the code:

<body bgcolor="#001F3E" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"
onLoad="runSlideShow(); doGIF()";
P7_Snap('AboutUsImg','AboutUsNav',0,12);P7_Snap('CommunitiesImg','CommunitiesNav',0,12)
;P7_Snap (continues...)">

I can't figure out what is wrong. The slideshow plays fine, but the navigation fly-outs aren't positioned correctly. Any suggestions?

[edited by: Woz at 1:41 am (utc) on Mar. 7, 2006]
[edit reason] Fixed Scrollism [/edit]

txbakers

8:48 pm on Mar 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



rather than list the various functions in the onLoad event itself, I would call one function that in turn calls the other functions.

use something like this in the <body> tag:

onLoad= "return getFuncs()"

and have getFuncs() run through all your scripts, then return true.

Pfui

9:10 pm on Mar 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Coincidentally, I found this the other day on the HTML Code Tutorial [htmlcodetutorial.com] site:

"Running Two (or more) Commands With onLoad [htmlcodetutorial.com]"

If you use G, etc., you'll find lots of similar info.

(By the way, that page's twin examples work with my older Netscape 7.X/Mac 9.X whereas some scripts do not.)

kaled

11:54 pm on Mar 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Keep your attributes simple - they're not meant to be used for such complex code. As suggested, create a wrapper function and call that instead.

You might think about removing the stray " after doGif()

Kaled.

kslnor

11:35 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



OK, I understand the general idea regarding calling a function, I'm just not sure how and where to place it within the code (yep, I'm a beginner).

Here are my questions:

1. does this: onLoad= "return getFuncs()"
mean I should have the line read as this, where all the functions are within the ():

<body bgcolor="#001F3E" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"
onLoad= "return getFuncs(runSlideShow(); doGIF();
P7_Snap('AboutUsImg','AboutUsNav',0,12);P7_Snap('CommunitiesImg','CommunitiesNav',0,12);
P7_Snap('PastProjectsImg','PastProjectsNav',0,12);
P7_Snap('HomeownersImg','HomeownersNav',0,12);
P7_Snap('FinancingImg','FinancingNav',-75,12))

2.Where do I put getFuncs()? under the <script> tag? Does anything go between the ()

3. "then return true" I'm not sure what you mean here.

Thank you

[edited by: Woz at 1:42 am (utc) on Mar. 7, 2006]
[edit reason] Fixed Scrollism [/edit]

kaled

1:23 am on Mar 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



function getFuncs()
{
runSlideShow();
doGIF();
P7_Snap('AboutUsImg','AboutUsNav',0,12);
P7_Snap('CommunitiesImg','CommunitiesNav',0,12);
P7_Snap('PastProjectsImg','PastProjectsNav',0,12);
P7_Snap('HomeownersImg','HomeownersNav',0,12);
P7_Snap('FinancingImg','FinancingNav',-75,12);
}

<body onload= "getFuncs(); return true">

NOTE
All the other body attributes ought really to be replaced with CSS.

Kaled.

kslnor

3:47 pm on Mar 8, 2006 (gmt 0)

10+ Year Member



Thanks, Kaled. I'm still not able to make this "get function" command work, though. Maybe something is interfering...maybe I just don't get it... Would you be willing to take a look at the entire code? Can I post the url to the page that contains the code (there's a lot of code)?

kaled

4:30 pm on Mar 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried opening a javascript console to look for errors?

Both Opera and Firefox will report errors. Opera, by default, normally opens a javascript console if an error occurs. In Firefox, you must open the console manually (look in the Tools menu).

Kaled.

kslnor

1:28 am on Mar 11, 2006 (gmt 0)

10+ Year Member



Thanks, Kaled. You have been very helpful but...I still can't get it to work correctly. I ran it through the java console, but nothing really came up. So, if anyone can assist, following is the code (please excuse the sloppyness of the images, links, etc. This is just a test to get the javascript working correctly). Maybe the several scripts are interfering? Thank you.

<snip>

<Edit by TrillianJedi>Please repost the code without the specifics. Way too much code there for me to edit and examplify ;)</Edit>

[edited by: trillianjedi at 9:00 am (utc) on Mar. 11, 2006]
[edit reason] See above [/edit]

kslnor

4:20 pm on Mar 11, 2006 (gmt 0)

10+ Year Member



Sorry TrillianJedi, here's the scaled-down version of the code. It's still a lot, but I tried to keep in the items that I thought would be helpful. Thanks.

<head>

<script type="text/JavaScript">
<!--

function MM_initTimelines() { //v4.0
//MM_initTimelines() Copyright 1997 Macromedia, Inc. All rights reserved.
var ns = navigator.appName == "Netscape";
var ns4 = (ns && parseInt(navigator.appVersion) == 4);
var ns5 = (ns && parseInt(navigator.appVersion) > 4);
var macIE5 = (navigator.platform? (navigator.platform == "MacPPC") : false) && (navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4);
document.MM_Time = new Array(1);
document.MM_Time[0] = new Array(1);
document.MM_Time["MenusOff"] = document.MM_Time[0];
document.MM_Time[0].MM_Name = "MenusOff";
document.MM_Time[0].fps = 15;
document.MM_Time[0][0] = new String("behavior");
document.MM_Time[0][0].frame = 4;
document.MM_Time[0][0].value = "MM_showHideLayers('AboutUsNav','','hide','BuySellNav','','hide','SpecialsTipsNav','','hide','AboutUsNav','','hide','FranchiseOppsNav','','hide','FranchiseNetNav','','hide','ContactUsNav','','hide','NewsNav','','hide')";
document.MM_Time[0].lastFrame = 4;
for (i=0; i<document.MM_Time.length; i++) {
document.MM_Time[i].ID = null;
document.MM_Time[i].curFrame = 0;
document.MM_Time[i].delay = 1000/document.MM_Time[i].fps;
}
}
//-->
</script>

<script type="text/JavaScript">
<script>
function gotoit(f){
for (var i=0; i < f.d.length; i++){
if (f.d[i].checked) {
location.href = f.d[i].value;
}
}
}
</script>

<script>

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 2000

// Duration of crossfade (seconds)
var crossFadeDuration = 10

// Specify the image files
var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below

Pic[0] = 'fireanimation.gif'
Pic[1] = 'folder.jpg'

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
preLoad[i] = new Image()
preLoad[i].src = Pic[i]
}

function runSlideShow(){
if (document.all){
document.images.SlideShow.style.filter="blendTrans (duration=2)"
document.images.SlideShow.style.filter="blendTrans (duration=crossFadeDuration)"
document.images.SlideShow.filters.blendTrans.Apply ()
}
document.images.SlideShow.src = preLoad[j].src
if (document.all){
document.images.SlideShow.filters.blendTrans.Play( )
}
j = j + 1
if (j < (p-1)) j=0
t = setTimeout('runSlideShow()', slideShowSpeed)
}
</script>

</head>

<body onLoad= "runSlideShow(); P7_Snap('AboutUsImg','AboutUsNav',0,12);P7_Snap('CommunitiesImg','CommunitiesNav',0,12);P7_Snap('AboutUsImg','Trigger',-50,-30);P7_Snap('CommunitiesImg','CommunitiesNav',0,12);P7_Snap('AboutUsImg','Trigger',-50,-30);P7_Snap

<div id="AboutUsNav" style="position:absolute; left:134px; top:119px; width:150; height:100; z-index:10; visibility: hidden">


class="linksOUT1" onMouseOver="this.className='linksOVER1'" onMouseOut="this.className='linksOUT1'" onClick="MM_goToURL('parent','/aboutus.shtml');return document.MM_returnValue">&nbsp;Our Story</td>
</tr>

</div>

<div id="TRIGGER" style="position:absolute; left:-2px; top:-4px; width:600px; height:27px; z-index:4; visibility: hidden; border: 1px none #000000">
<a href="javascript:;" onMouseOver="doTrigger()"><img src="/images/spacer.gif" width="100%" height="100%" border="0"></a>
</div>


<td valign="top"><img src="/images/nfnav_1.jpg" width="558" height="14"><br><img src="/images/nfnav_2b.jpg" width="24" height="18"><a href="#" onMouseOver="MM_showHideLayers('AboutUsNav','','show','CommunitiesNav','','hide','PastProjectsNav','','hide','HomeownersNav','','hide','FinancingNav','','hide','ContactUsNav','','hide');undoTrigger();MM_timelineStop()"><img src="/images/nfnav_aboutus.jpg" name="AboutUsImg" width="68" height="18" border="0" id="AboutUsImg"></a><a href="#" onMouseOver="MM_showHideLayers('AboutUsNav','','hide','CommunitiesNav','','show','PastProjectsNav','','hide','HomeownersNav','','hide','FinancingNav','','hide','ContactUsNav','','hide');undoTrigger();MM_timelineStop()"><img src="/images/nfnav_communities.jpg" name="CommunitiesImg" width="86" height="18" border="0" id="CommunitiesImg"></a>
</td>
</tr>
</table>

<--THIS RELATES TO THE FUNCTION GOTOIS(F) SCRIPT -->

<table border="0" bordercolor="" width="779px" bgcolor="">

<tr>
<td valign="top" align="left" width="140" bgcolor="" rowspan="2" style="border:solid 1px #924c3c">&nbsp&nbsp <center><img src="smallmichigan.jpg" width="100" height="126"><br><br><B><font size="2" face="verdana, arial, times new roman">Find a Norfolk Home</B></font></center>
<font size="1" face="verdana, arial, times new roman">
<form name="gotoform">
<input type="radio" name="d" value="pageone.htm" /> Ann Arbor, MI<br>
<input type="radio" name="d" value="pagetwo.htm" /> Dexter, MI<br>
<input type="radio" name="d" value="pagethree.htm" / > Grass Lake, MI<br>
<input type="radio" name="d" value="pagefour.htm" / > Jackson, MI<br>
<input type="radio" name="d" value="pagefive.htm" / > View All Homes<br><br>
<center><input type="button" value="Find a Home" onClick="gotoit(this.form)"></center>
</form>
</td>
<td></td>

<--THIS RELATES TO THE FUNCTION RUNSLIDESHOW() SCRIPT -->

<td valign="top" align="right" rowspan="2" ><img src="fireanimation.gif" name='SlideShow' width="593" height="395">
</td>
</tr>
</table>
</body>
</html>