<html>
<head>
</head>
<body bgcolor=#ffffff>
<center>
<img src="home.gif" name="pic1" width=200 height=100>
</center>
<p>
<form name="myForm">
Name:
<input type="text" name="name" value=""><br>
e-Mail:
<input type="text" name="email" value=""><br><br>
<input type="button" value="Push me" name="myButton" onClick="alert('Yo')">
</form>
<p>
<center>
<img src="ruler.gif" name="pic4" width=300 height=15>
<p>
<a href="http://rummelplatz.uni-mannheim.de/~skoch/">My homepage</a>
</center>
</body>
</html>
Here is a screenshot of this page (I have added some things):
We have two images, one link and a form with two text fields and a button. From JavaScript’s
point of view the browser window is a window-object. This window-object contains certain elements
like the statusbar. Inside a window we can load a HTML-document (or a file from another
type - we will restrict ourselves to HTML-files for now). This page is a document-object. This
means the document-object represents the HTML-document which is loaded at the moment.
The document-object is a very important object in JavaScript - you will use it over and over
again. Properties of the document-object are for example the background color of the page. But
what is more important is that all HTML-objects are properties of the document-object. A
HTML-object is for example a link, or a form. The following image illustrates the hierachy created
by our example HTML-page:
We want to be able to get information about the different objects and manipulate them. For this
we must know how to access the different objects. You can see the name of the objects in the
hierarchy. If you now want to know how to address the first image on the HTML-page you have
to look at the hierarchy. You have to start from the top. The first object is called document. The
first image the page is represented through
through JavaScript with
entered into the first form element you must first think about how to access this object. Again
we start from the top of our hierarchy. Follow the path to the object called
the names of the object you pass together. This means you can access the first textelement through: