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 7 Example 1: OnClick call alert Function


Click on the button to see the alert box pop up!

 


The form is made with normal HTML code. The only difference is: OnClick="alert1()" OnClick represents an event, in this case a mouse click, that needs to performed to call the function. alert1() is the name of the function which has already been defined in the HEAD of the document.

<BODY>
<form>
<input TYPE="button"
VALUE="Click Me"
ONCLICK="alert()">
We know that there is a function because of the () -two brackets at the end of the ONCLICK line. The function is only a name however, and we must give it some code. The code must be between {}. Don't forget this is done in the <head></head> part of the document. The code is on the right.

<HEAD>
<Script Language="JavaScript">
<!--//
function alert()
{alert("You Clicked!");}
//-->

</Script>
</HEAD>

back button
next button

© 2002 Tracy Johnson