What is JavaScript?
JavaScript was created by Netscape Communications as a combination
of Java and HTML. It is a scripting language that allows web pages to
become more interactive. Unlike Java applets that have to be compiled
first before being added to a page, JavaScript is interpretted by the browser and doesn't require any additional developing tools. When using JavaScript, all code must be placed
in between the tags <SCRIPT> and </SCRIPT>. There are
certain JavaScript commands that do not need to go between these
tags (such as some of the mouse commands covered later).
This tutorial will cover how JavaScript can do some of the same things HTML can do such as writing text on the screen and setting the background color. Knowing some of these basics covered in the next several tutorials will allow you to write your own scripts.
Writing Text
We can write text using JavaScript by using document.write( ). The
text to be written goes in ( ), and is enclosed in quotes. This is how it
will look:
<SCRIPT>
document.write("Put text here")
</SCRIPT>
And here is how it will look on the screen:
We can combine HTML with JavaScript to change the appearance of the
text. If we wanted to underline the text here is what our example would
look like:
<SCRIPT>
document.write("<U>Put text here</U>")
</SCRIPT>
And here is what it will look like:
Setting The Background Color
JavaScript can also be used to set the background color of the page. You can also use the idea to dynamically change the background color if a certain link or picture is clicked as described in the Mouse Commands Tutorial.
To do this we use document.bgColor="color". For a list of colors
refer to the color chart. Here is what it will
look like:
<SCRIPT>
document.bgColor="red"
</SCRIPT>
This page has been accessed
times since June 24, 2001
Last Updated March 15, 2001
|