Solved

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

Posted on 2011-09-28
6
271 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How does Redux fit into React? 3 66
VS2015 Redefinition errors 4 25
jQuery not working on ELSE... why? 2 19
Detect change of Select using JavaScript Only 12 45
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

914 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now