Layout ] Multimedia ] Programming ] Scripting ] Communicate ] Navigation ]

Chapter 1

Up ] [ Chapter 1 ] Chapter 2 ] Chapter 3 ] Chapter 4 ] Chapter 5 ]

 

What You Need, How To Get Started

JavaScript is incredibly cost effective, in that it requires absolutely nothing which is not freely available on the Internet.  In fact, most computers already have most of what is needed.  The tools necessary for writing JavaScript are the following:

  1. A Text-Editor.  Any word-processor (ex. Word, Works, Word Perfect) will do.   Notepad, Write or Wordpad are also fine, and at least one of these is installed on almost every PC.  For Unix, some possibilities are ed, vi, emacs, or pico.  I like Pico for Unix, and Notepad for Windows.  Some that are available for download are SitePad (trial) and Super NoteTab.  Most HTML editors will works as well, provided that they let you edit the HTML source.
  2. An Internet Browser which supports JavaScript.  That usually means Internet Explorer or Netscape Navigator version 3 or greater (Netscape 2 supports some JavaScript, but there are many new features which were not in that version).

JavaScript is a scripting language.  In this case, that means that it doesn't really do anything on its own, it is dependant on a webpage.  You write the JavaScript into the HTML document, usually within a Script tag.  A simple example of this follows.

<HTML>
<BODY>
<P>This is a JavaScript Test.<BR>
<FORM>
<SCRIPT LANGUAGE="JavaScript"></SCRIPT>
<INPUT TYPE=BUTTON VALUE="Click Here" NAME=Button1
OnClick="alert('This is a message.')">
</FORM>
</BODY>
</HTML>

Try to visualize what the page will look like, and then guess what it will do. When you're ready, click on the frame below to see a preview of this HTML.

Now, if you wanted to make this page, or any other page with scripts, there are several steps you would follow.  This process often becomes instinctive after working with several pages.

  1. Enter text into the editor, and save it.
  2. Open the new version of the document into a browser.  Some editors have built-in preview functions, such as FrontPage 98, while others have a toolbar button or menu item to automatically open it in the browser, such as Super NoteTab.  With some, like Notepad, you need to do it manually.  After the first time you open the document, if you leave it open, you can just refresh the document to see the new version.  On many browsers, pressing F5 refreshes.
  3. Test the document, and see if it works as you wanted it to.  If not, repeat.

Try it now.  Open your editor and enter the script, either by copying and pasting it from this page, or typing it in.  Save it, and open it in the browser.  Since it has already been debugged, it should run fine.


In this example, only one method of calling JavaScript code in a document is shown.   For this method, the scripting language must be determined by inference.  The language of the previous SCRIPT tag is used.

Notice that I used double quotes on the outside, and single quotes on the inside.   It doesn't matter which you use as long as you are consistent.  I like to use double quotes as much as possible, and thus use single quotes to enclose these sections of code.

There are other methods to do this, but this is the most commonly used and supported method for JavaScript. Further information on how to use the SCRIPT tag can be found in the SCRIPT tag syntax.

JavaScript, UN-like HTML, is case-sensitive.  It cares whether you use upper of lower case, except within quotation marks.  document, document, and document are all treated differently.

Where you place line breaks is totally up to you, other than that a string in quotes should all be on one line.  After each statement, you should end it with a semicolon ";".  That's how it knows where the divisions are.  Also, you can group several statements together with braces "{ ... }"

Up ] Next ]
Layout ] Multimedia ] Programming ] Scripting ] Communicate ] Navigation ]
[ Chapter 1 ] Chapter 2 ] Chapter 3 ] Chapter 4 ] Chapter 5 ]

The Web Wizard's Spellbook © 1998, Team WWS