Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

js. How to start multiple javascript function on rge body onload function

Posted on 2011-09-28
6
277 Views
Last Modified: 2012-05-12
I need to know how to start multiple JS functions during the body onload

I have these javascript function
<SCRIPT LANGUAGE="JavaScript">
function auto1()
"""
</script>

<SCRIPT LANGUAGE="JavaScript">
function auto2()
''''''
</script>
----------------------------

If I add the script for auto2 how can I get it to run.. I tried <body onload="auto1();auto2()">
and it did not work only auto1 worked.

========================Blow is the script for auto1========================
<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Mike Canonigo (mike@canonigo.com) -->
<!-- Web Site:  http://www.munkeehead.com -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
NewImg = new Array (
"images/FUN-1.jpg",
"images/FUN-2.jpg",
"images/FUN-3.jpg",
"images/FUN-4.jpg"
);
var ImgNum = 0;
var ImgLength = NewImg.length - 1;

//Time delay between Slides in milliseconds
var delay = 5000;

var lock = false;
var run;
function chgImg(direction) {
if (document.images) {
ImgNum = ImgNum + direction;
if (ImgNum > ImgLength) {
ImgNum = 0;
}
if (ImgNum < 0) {
ImgNum = ImgLength;
}
document.slideshow1.src = NewImg[ImgNum];
   }
}
function auto1() {
if (lock == true) {
lock = false;
window.clearInterval(run);
}
else if (lock == false) {
lock = true;
run = setInterval("chgImg(1)", delay);
   }
}
//  End -->
</script>


<body onload="auto1()">

Open in new window

0
Comment
Question by:westdh
  • 3
  • 2
6 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36718480
<body onload="auto1();auto2()">

Open in new window

or
<body onload="autos()">

<SCRIPT LANGUAGE="JavaScript">
function autos() {
       auto1();
       auto2();
}
</script>

Open in new window

or
<body>

<SCRIPT LANGUAGE="JavaScript">
window.onload = function() {
       auto1();
       auto2();
}
</script>

Open in new window

0
 
LVL 18

Expert Comment

by:nap0leon
ID: 36718720
@leakim971
Curious - which of these will run synchronously versus asynch? ("one-after-the-other" versus "at the same time")
0
 

Author Comment

by:westdh
ID: 36719000
asynch ("at the same time")
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:westdh
ID: 36719084
Tried all three. None worked
0
 

Author Closing Comment

by:westdh
ID: 36719868
thanks
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36720273
>@leakim971
>Curious - which of these will run synchronously versus asynch? ("one-after-the-other" versus "at the same time")

@nap0leon : no one.

@westdh, I apologize if I misunderstanding your question. I saw the new one about running both at what humans call << the same time >>
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Grunt script for Build Process 1 42
Javascript the "if condition with Or" 8 29
How to add a stringified JSON string to an IP address? 11 57
Input parameteres to DragOver 2 19
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question