Javascript-Lesson 1

Application

Introduction

Like CSS, Javascript can appear in three forms. Inline, internal and external. Inline scripts are actions that are carried out as the browser loads the page. If the result of the script is to wait for some reaction from the user, e.g. moving the mouse pointer over something on the page, then the script is put into the head portion of the page.

Inline

Here is the way to apply an inline Javascript:
<body>
<script type="text/javascript">
Javascript goes here
</script>
</body>
Scripts written into the body are executed as the page loads into the browser.

Internal

Scripts in the head are encased in the same way as inline scripts:
<head>
<script type="text/javascript">
Javascript goes here
</script>
</head>
Scripts in the head wait until called for.

External scripts

Where scripts apply to several pages, the script can be put in a separate file with the extension '.js'. The file script is accessed by using:
<script src=" scrpt_file_name.js "></script>
Remember that this code must go in the head or body according to where the external file script would go if it were in the web page.

Statements

Each statement is a command to the browser. Statements should either be one to a line or should end with a semi-colon. Very often a javascript programmer will put only one statement on a line and end the line with a semi-colon.

Blocks

A group of related statements can form a block. A block is encased in curly brackets '{' and '}'. E.G.

<script type="text/javascript">
{
document.write("<h1>Greetings</h1>");
document.write("<p>Hullo World</p>");
}
</script>
Previous Lesson previous lesson next lesson Next Lesson