Lab I: Javascript and Cookies

Part I: Simple JavaScript

What is JavaScript? JavaScript is a programming language that allows you to add functionality to a web page. Despite its name, Java and JavaScript are quite different. JavaScript is somewhat simpler, and there are many sites on the web with JavaScripts that you can modify for your own purposes. Unlike Java, Javascript commands are placed directly in the html file and there is no need for a separate "compiler" to translate the programming instructions. Rather, Javascript is "interpreted" directly by the browser. Some developers use Javascript in conjunction with "Cold Fusion" to create an interface between web pages and databases for ecommerce (and other) applications.

How do I make a JavaScript? Before beginning, you must be able to login to your mason account and you must have a public_html directory. If you already have a public_html directory, do not create another one. (Ask your TA for help if you are unsure or use the Unix command ls to list the contents of your mason account.)

To create a public_html directory:

(login)
chmod  a+x  .            (don't forget the spaces and the dot)
mkdir  public_html       (use an underscore, not an hyphen)
chmod  a+rx  public_html
Now you are ready to try the simple Javascript exercise below:

Important Note: JavaScript is "case sensitive." This means you must be especially careful when typing in JavaScripts.

JavaScript commands go inside <script> </script> tags. These scripts may go in the head or body section of the html document. Note: Click here for help with the pico text editor.

Sample Script

(login)
cd public_html
pico myscript.html
(then enter the file below)

<html>
<head>
<!--Simple Java script written by (your name) on (today's date)-->
<title>This is a JavaScript Test</title>
</head>

<body>
<script>
document.write("Hello world!")
</script>
</body>
</html>
 
(type control x, save and exit)
chmod a+r myscript.html
Then go to your web browser and enter this url:
http://mason.gmu.edu/~yourloginname/myscript.html
Your script should appear. If it doesn't ask your TA or instructor for help.

For more information on JavaScript, see
T. Negrino and D. Smith, JavaScript for the World Wide Web, 4th edition, Peachpit Press, 2001.

www.javascripts.com

Part II: Simple JavaScript

Now you are ready to do part II: Cookies.


Click here to return to the IT 108 page
Copyright © 1999-2002 All Rights Reserved