Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 functions on onLoad? 2

Status
Not open for further replies.

Jeanne

Technical User
Jan 15, 2001
45
0
0
US
I am pretty new to JavaScript, and I am sure my questions are pretty basic. Can I have more than one function on onLoad and if so, how do I do it? My body tag looks like this:

<BODY BGCOLOR=#000000 ONLOAD=&quot;preloadImages();&quot;>

I want to add:

onLoad=&quot;redirect&quot;

Also, if I have more than one thing I want to do in JS do add all of the code in one SCRIPT tag or should I add each separately?

Thanks for helping me with what I believe to be very basic questions.

Jeanne
 
One way is to call ONE function in your onLoad and have that function call the other two.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Wow! you are super fast! Thanks!

I am an idiot when it comes to JS, I basically only know HTML. Could you please show me the code to do that?

The code for my page is:

<HTML>
<HEAD>
<TITLE>Thank You!</TITLE>
<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html; charset=iso-8859-1&quot;>


<!-- ImageReady Preload Script (Interactivity Master.psd) -->
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--

function newImage(arg) {
if (document.images) {
rslt = new Image();
rslt.src = arg;
return rslt;
}
}

function changeImages() {
if (document.images && (preloadFlag == true)) {
for (var i=0; i<changeImages.arguments.length; i+=2) {
document[changeImages.arguments].src = changeImages.arguments[i+1];
}
}
}

var preloadFlag = false;
function preloadImages() {
if (document.images) {
interactive_14_16over = newImage(&quot;images/interactive_14_16over.jpg&quot;);
interactive_14_17over = newImage(&quot;images/interactive_14_17over.jpg&quot;);
interactive_14_18over = newImage(&quot;images/interactive_14_18over.jpg&quot;);
interactive_14_20over = newImage(&quot;images/interactive_14_20over.jpg&quot;);
interactive_14_21over = newImage(&quot;images/interactive_14_21over.jpg&quot;);
interactive_14_22over = newImage(&quot;images/interactive_14_22over.jpg&quot;);
interactive_14_19over = newImage(&quot;images/interactive_14_19over.jpg&quot;);
interactive_15_23over = newImage(&quot;images/interactive_15_23over.gif&quot;);
interactive_15_24over = newImage(&quot;images/interactive_15_24over.gif&quot;);
preloadFlag = true;
}
}

// -->
</SCRIPT>
<!-- End Preload Script -->

<!--Redirect Script -->
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
function redirect () { setTimeout(&quot;go_now()&quot;,5000); }
function go_now ()
{ window.location.href = &quot; }
//-->
</SCRIPT>

</HEAD>
<BODY BGCOLOR=#000000 ONLOAD=&quot;preloadImages();&quot;>
<!-- ImageReady Slices (Interactivity Master.psd) -->
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=59 HEIGHT=1></TD>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=2 HEIGHT=1></TD>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=49 HEIGHT=1></TD>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=50 HEIGHT=1></TD>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=48 HEIGHT=1></TD>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=53 HEIGHT=1></TD>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=46 HEIGHT=1></TD>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=12 HEIGHT=1></TD>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=38 HEIGHT=1></TD>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=50 HEIGHT=1></TD>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=203 HEIGHT=1></TD>
<TD></TD>
</TR>
<TR>
<TD COLSPAN=11> <IMG SRC=&quot;images/interactive_01_01.gif&quot; WIDTH=610 HEIGHT=10></TD>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=1 HEIGHT=10></TD>
</TR>
<TR>
<TD ROWSPAN=3> <A HREF=&quot;interactive.html&quot;
ONMOUSEOVER=&quot;changeImages('interactive_14_14', 'images/interactive_14_16over.jpg'); return true;&quot;
ONMOUSEOUT=&quot;changeImages('interactive_14_14', 'images/interactive_14_14.jpg'); return true;&quot;>
<IMG SRC=&quot;images/interactive_02_02.jpg&quot; WIDTH=59 HEIGHT=51 BORDER=0 alt=&quot;interactivity&quot;></A></TD>
<TD COLSPAN=2 ROWSPAN=2> <A HREF=&quot;service.html&quot;
ONMOUSEOVER=&quot;changeImages('interactive_14_14', 'images/interactive_14_17over.jpg'); return true;&quot;
ONMOUSEOUT=&quot;changeImages('interactive_14_14', 'images/interactive_14_14.jpg'); return true;&quot;>
<IMG SRC=&quot;images/interactive_03_03.jpg&quot; WIDTH=51 HEIGHT=50 BORDER=0 alt=&quot;Graphics Universal service&quot;></A></TD>
<TD ROWSPAN=2> <A HREF=&quot;output.html&quot;
ONMOUSEOVER=&quot;changeImages('interactive_14_14', 'images/interactive_14_18over.jpg'); return true;&quot;
ONMOUSEOUT=&quot;changeImages('interactive_14_14', 'images/interactive_14_14.jpg'); return true;&quot;>
<IMG SRC=&quot;images/interactive_04_04.jpg&quot; WIDTH=50 HEIGHT=50 BORDER=0 alt=&quot;film output, proofing&quot;></A></TD>
<TD ROWSPAN=2> <A HREF=&quot;asset.html&quot;
ONMOUSEOVER=&quot;changeImages('interactive_14_14', 'images/interactive_14_19over.jpg'); return true;&quot;
ONMOUSEOUT=&quot;changeImages('interactive_14_14', 'images/interactive_14_14.jpg'); return true;&quot;>
<IMG SRC=&quot;images/interactive_05_05.jpg&quot; WIDTH=48 HEIGHT=50 BORDER=0 alt=&quot;image asset management&quot;></A></TD>
<TD ROWSPAN=2> <A HREF=&quot;capture.html&quot;
ONMOUSEOVER=&quot;changeImages('interactive_14_14', 'images/interactive_14_20over.jpg'); return true;&quot;
ONMOUSEOUT=&quot;changeImages('interactive_14_14', 'images/interactive_14_14.jpg'); return true;&quot;>
<IMG SRC=&quot;images/interactive_06_06.jpg&quot; WIDTH=53 HEIGHT=50 BORDER=0 alt=&quot;digital capture, image capture, scanning, digital scanning&quot;></A></TD>
<TD ROWSPAN=2> <A HREF=&quot;past.html&quot;
ONMOUSEOVER=&quot;changeImages('interactive_14_14', 'images/interactive_14_21over.jpg'); return true;&quot;
ONMOUSEOUT=&quot;changeImages('interactive_14_14', 'images/interactive_14_14.jpg'); return true;&quot;>
<IMG SRC=&quot;images/interactive_07_07.jpg&quot; WIDTH=46 HEIGHT=50 BORDER=0 alt=&quot;gui history&quot;></A></TD>
<TD COLSPAN=2 ROWSPAN=2> <A HREF=&quot;vision.html&quot;
ONMOUSEOVER=&quot;changeImages('interactive_14_14', 'images/interactive_14_22over.jpg', 'interactive_15_15', 'images/interactive_15_23over.gif'); return true;&quot;
ONMOUSEOUT=&quot;changeImages('interactive_14_14', 'images/interactive_14_14.jpg', 'interactive_15_15', 'images/interactive_15_15.gif'); return true;&quot;>
<IMG SRC=&quot;images/interactive_08_08.jpg&quot; WIDTH=50 HEIGHT=50 BORDER=0 ALT=&quot;graphics universal vision&quot;></A></TD>
<TD COLSPAN=2> <IMG SRC=&quot;images/interactive_09_09.gif&quot; WIDTH=253 HEIGHT=1></TD>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=1 HEIGHT=1></TD>
</TR>
<TR>
<TD ROWSPAN=2> <A HREF=&quot;contact.html&quot;
ONMOUSEOVER=&quot;changeImages('interactive_15_15', 'images/interactive_15_24over.gif'); return true;&quot;
ONMOUSEOUT=&quot;changeImages('interactive_15_15', 'images/interactive_15_15.gif'); return true;&quot;>
<IMG SRC=&quot;images/interactive_10_10.jpg&quot; WIDTH=50 HEIGHT=50 BORDER=0></A></TD>
<TD ROWSPAN=2> <IMG SRC=&quot;images/interactive_11_11.gif&quot; WIDTH=203 HEIGHT=50></TD>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=1 HEIGHT=49></TD>
</TR>
<TR>
<TD> <A HREF=&quot;interactive.html&quot;
ONMOUSEOVER=&quot;changeImages('interactive_14_14', 'images/interactive_14_16over.jpg'); return true;&quot;
ONMOUSEOUT=&quot;changeImages('interactive_14_14', 'images/interactive_14_14.jpg'); return true;&quot;>
<IMG SRC=&quot;images/interactive_12_12.jpg&quot; WIDTH=2 HEIGHT=1 BORDER=0></A></TD>
<TD COLSPAN=7> <IMG SRC=&quot;images/interactive_13_13.gif&quot; WIDTH=296 HEIGHT=1></TD>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=1 HEIGHT=1></TD>
</TR>
<TR>
<TD COLSPAN=11>
<div align=&quot;center&quot;>
<p><font face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;3&quot; color=&quot;#FFFFFF&quot;>You
are now subscribed to the Graphics Universal, Inc. Newsletter.<br>
We look forward to providing you with our latest ideas and innovations.
</font></p>
<p><font color=&quot;ffffff&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>If you would
like specific information on our products or services, please click
on the &quot;Contact&quot; icon</font><font face=&quot;Arial, Helvetica, sans-serif&quot;>
</font> <font color=&quot;ffffff&quot; face=&quot;Arial, Helvetica, sans-serif&quot;> on
any page of our website, or click<a href=&quot;contact.html&quot;> <font color=&quot;#00CCFF&quot;>here.</font></a></font></p>
<p><font color=&quot;#00CCFF&quot;><img src=&quot;GUICOLOR.gif&quot; width=&quot;150&quot; height=&quot;86&quot;></font></p>
<p><font face=&quot;Arial, Helvetica&quot; color=&quot;ffffff&quot;>12437 East 60th Street,
Tulsa, Oklaho</font><font face=&quot;Arial, Helvetica&quot;><font color=&quot;ffffff&quot;>ma
74146 1-800-876-4484 or 918-461-0609 </font></font><font face=&quot;Arial, Helvetica&quot; color=&quot;ffffff&quot;>Email:
</font><font color=&quot;ffffff&quot;><a href=&quot;mailto:sales@calvertco.com&quot;><font face=&quot;Arial, Helvetica&quot; color=&quot;#00CCFF&quot;>graphicsuniversal@calvertco.com</font></a>&copy;2001
Graphics Universal, Inc.</font></p>
</div>
</TD>
<TD> <IMG SRC=&quot;images/spacer.gif&quot; WIDTH=1 HEIGHT=394></TD>
</TR>
</TABLE>
<!-- End ImageReady Slices --><font color=&quot;#6666FF&quot;><a href=&quot; color=&quot;#FF0000&quot;>
<font size=&quot;3&quot;>Employment Opportunities </font></font></a> </font>
</BODY>
</HTML>
 
Add the following to in your HEAD section:
Code:
SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
function loader () { 
   preloadImages();
   redirect();
//-->
</SCRIPT>
Put the two function calls above in whichever order is required. Then, change your onLoad to:
Code:
onLoad=&quot;loader()&quot;
To answer your other question: I don't think it really matters whether you use multiple <script> tags or put everything in one. The scripts are evaluated as they are encountered. You can even mix <script src=&quot;...&quot;> with inline javascript.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
You are too cool. Thank you so much for the help!

Jeanne
 
You are quite welcome. Let us know how it works out.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
It works great. Thank you very much.

I couldn't get it to work at first, but then I noticed that the closing bracket wasn't there, I added it - and then it worked like a charm!

Now I need to get my cookies working....

Thanks again,

Jeanne
 
Oops! Mea culpa! :~/ Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top