Tutorial #2 - writing JavaScript applications.

Throughout this tutorial, I have color coded the scripts, to make them easy to understand. Here is the list of colors.
Objects
Properties
Methods
Event Handlers
Variables
Statements

A javascript is a piece of technical coding which tells the browser ( a browser is the program that you are viewing this page with - e.g. Microsoft Internet Explorer ) to do something. Something of this nature is called a method. A method gives instructions to the browser. As with any javascript coding, the technical part of it is placed between two tags:


<script language="javascript">
<!--Hide from javascript unable browsers
and

//End hiding-->
</script>
These tags tell the browser that the coding between the tags is a programming language called javascript. The <!--Hide from javascript unable browsers part and the //End hiding--> tells javascript unable browsers not to show the coding between them. Javascript unable browsers don't understand the tags so they would normally just write out the coding onto the page.

Below, is a very simple script. It's effect is just to write out the text between the double quotes.


<script language="javascript">
<!--Hide from javascript unable browsers
document.write("Write out this text!")
//End hiding-->
</script>
This script has one simple line of coding in it. document is the object that the method (write()) affects. The write() method will write whatever is between the brackets. Because, in this example we wanted to write out plain text, we put the text in double quotes. You would also put tags in double quotes.
For example:

<script language="javascript">
<!--Hide from javascript unable browsers
document.write("<body>")
//End hiding-->
</script>
You will now be asking what the point of all of this is - all it does is write out tags or text. This script is just an introductry script so you will find out later... ...okay, I'll tell you now. You may want the javascript to find out what browser the user is using and then you may want the browser to write the name of it out. Try doing that with just HTML! There are hundreds ( almost ) of different things that you could do with this property and method. Don't get methods mixed up with functions. We'll come onto functions in the later tutorials. Onto the next tutorial.

JavaScript Tutorial #3 Variables and properties.
Back to contents.

Copyright � Jonathan Green.
All rights reserved.