Some common ways to trigger JavaScript Functions

Remember that JavaScript functions always have specific names.

One of the challenges you have to meet is figuring out how you can get your functions to run. What are your choices for triggering a JavaScript function?
The following outlines a few common choices...


4 examples: Some things that trigger a JavaScript function to "run" (also referred to as activating the function, calling the function, etc.):



1) a function name sitting by itself outside of another function - within the script tags in the head or body of the page
(if you see a function name inside another function, that also is a way to run a function -- the function name that is inside is activated at that point)
eg:

getInfo();

2) an onload command inside the actual body tag calling a function
eg:

<body onload="changeColour();">

3) a document write command calling a function within script tags like below in the body of the page:
eg:

<script language="javascript">
document.write(showDateTime());
</script>

4) a command (like onclick or a rollover command like onmouseover or onmouseout, etc.) calling a function in a link or in a form button
eg:

<a href="#" onclick="window.location=choosePage(); return false;">Here!</a>

OR

<form> <input type="button" value="Hello Lovely World" onclick="HelloWorld();"> </form>