::: Tutorials > JavaScripts

Embedding JavaScripts in your code
How to insert JavaScripts into your souce code to add dynamics to the page


Tutorial by Gleb
Tuesday April 3, 2003


JavaScript is an object based scripting language for making both client and server applications. Therfore it adds interactivity to your pages and makes them more interesting. The first thing you have to know about JavaScript is how to embed it into your source.
There are two simple ways to embed Javascipts:
  1. Using the <SCRIPT></SCRIPT> tags.
  2. Specify the source of JavaScript file

SCRIPT TAG

When we are using the SCRIPT tags. We should specify the language we are using as an atirbute of SCRIPT. All the JavaScript code goes inside this tag. Note: Some of the early browsers don't recognize JavaScript if its not inside of the COMMENT tag. Though you don't have to do that with new ones.

Example:
<SCRIPT language="JavaScript">
<!--
Code goes here
//-->
</SCRIPT>

Specifying the souce of JavaScript file

You can write your code in an its own file and save it as .js and then link to in your code. To do this you should add SRC attribute to the SCRIPT tag.

Example:
<!--
<SCRIPT SRC="yourjavascriptcodefile.js">
Nothing Should be here
</SCRIPT>
//-->

There should be nothng between the <SCRIPT SRC="source.js">>/SCRIPT>, because those insturctions would be ignored.

(Some of the contents are exceprts from JavaScript 1.1 Guide by Netscape Communications Corp.)


Copyright 2002 BLUEPRINT Los Altos High School Web Club. All rights reserved.
201 Almond Ave. Los Altos, CA 94022