JavaScript

Tuesday April 8, 2025
updated: April 10, 2002

 
Home
Getting Started
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Resources
Credits

 

 


  Lesson 2 Example: JavaScript Placement

Code Placed in BODY:

<html>
<head>
</head>

<body>
<script>
alert("This alert box appeared automatically when the page loaded because the script is placed in the BODY")
</script>

</body>
</html>

Result:

The alert box loaded automatically when this page was loaded. You did not have to trigger the event.

Code Placed in HEAD:

<html>
<head>
<script>
function message()
{alert("This alert box was called with the onclick event")}
</script>
</head>

<body>
<input type="button" value="click" onClick="message()">

</body>
</html>

 

back button
next button

© 2002 Tracy Johnson