The most important thing to know about using JavaScript is where to place it in your webpage. Ultimately this will be based on what your code does and when it needs to trigger. The two places in a website that JavaScript can be placed is the head section and the body section. If you want the scripts to run when the page is loaded place your script code in the “body” section of your website. If you are creating functions that need to be called or triggered by event, this code will go in the head section. It will load when the page loads, but must wait for a function call to activate it. You can use both header scripts and body scripts in your page. There is no limit on the amount of JavaScript your page can contain.
A basic function call would be something as seen below. The JavaScript code is in the head section and does not run until it is called by the onload event of the body section.
<html>
<head>
<script type="text/javascript">
function showAnAlertBox()
{
alert("The alert() is a built in method that displays a message box.");
}
</script>
</head>
<body onload="showAnAlertBox()">
</body>
</html>
You can also save your script code into a text document and refer to it in you webpage. This would be a good way to cut down redundant code and keep the code readable.
<html>
<head>
<script type="text/javascript" src="functions.js"></script>
</head>
<body>
</body>
</html>
534e11d0-151b-4608-83e6-03569cc4876b|0|.0