JCL's Tutorial On JavaScript Alerts

Note : If a dialogue box did not pop up, you are not using a high enough browser. You need Netscape or Internet Explorer 2.0.2 or higher.
Also Note : If you want this alert on your page, but do not want to read this tutorial, click here.

Creating JavaScript Alerts

Creating JavaScript Alerts is one of the easiest JavaScript commands to learn. Place this script in your HTML document under the <html> tag. Below is the code I used to make mine.


<script language = "JavaScript">
<!-- Begin hiding here --

/******************************************************************************************
This script is created and ©1997 by Jason Schanker (jcheetah@orion.webspan.net).
This script comes from "http://www.webspan.net/~herbs/jcheetah/web_design/javascript/alert".
You may copy this source freely if these comments remain in the script.
******************************************************************************************/

alert("Here Is A JavaScript Alert. You Can Make It Say Whatever You Want. Press OK To Learn How To Create It.");

// -- End hiding here -->
</script>

What The Above Code Means

<script language = "JavaScript">

All this does is tell the computer the language that is going to be used. You must use this tag, <script>, or <script = "JavaScript"> to make this Alert or any other JavaScript work.

<!-- Begin hiding here --

Since some browsers can't read JavaScript, they just read over the JavaScript code as text and show it to the user as text. This fragment of code begins the commenting out of this text if the user's browser cannot read JavaScript.

/******************************************************************************************
This script is created and ©1997 by Jason Schanker (jcheetah@orion.webspan.net).
This script comes from "http://www.webspan.net/~herbs/jcheetah/web_design/javascript/alert".
You may copy this source freely if these comments remain in the script.
******************************************************************************************/

These are a bunch of comments which must be left in here if you use this script. The /*,anything after it and before */ are comments. When the computer gets to this part, it skips over it.

alert("Here Is A JavaScript Alert. You Can Make It Say Whatever You Want. Press OK To Learn How To Create It.");

This command activates the Alert by activating the function called alert(). The alert() function does not have to be defined since it is a predefined function (a compiled function which was built into the JavaScript Language). The function returns the value in its parentheses in an Alert box. In this case, it returned, Here Is A JavaScript Alert. You Can Make It Say Whatever You Want. Press OK To Learn How To Create It. It doesn't return the quotes since the quotes is the JavaScript way of telling the computer that the text inside is a string (series of characters). You can separate the text into different lines by using the "\n" command in quotes. You can also include a variable (a letter or series of characters that stands for a varying value) by keeping the variable in parenthese, but out of quotaiton marks. You can also include a string and a variable by separating the string and variable with a "+". For example, if you had a variable called name which stood for "Jack", alert("Hello," + name + "!"); would give you an alert that would say, "Hello, Jack!". You can make the JavaScript Alert say anything. You can even make it say something like "You Are A Loser!" and the only button the visitor can press is OK! To change the message for your own needs, delete the message in the quotation marks and type your own, but don't delete the quotation marks or the parentheses.

// -- End hiding here -->

This ends the commenting out for browsers unable to read JavaScript.

</script>

This command tells the computer that the end of the JavaScript source has been reached. If you do not include this in your document source, the rest of your HTML document will be considered as JavaScript, and the computer will not be able to comprehend the rest of the document. Also, the computer will give you Error Alerts.

JCL's HTML & JavaScript Tutorial
E-Mail Me