This is a simplified account of Graphical User Interfaces in terms of Objects and Events. The input to and output from a JavaScript program is via a Graphical User Interface or GUI. The function of JavaScript is to enhance the standard GUI provided by HTML browsers by incorporating event-driven interaction, i.e. GUI manipulation and animation, as well as calculation controlled by the user.
A GUI has two main types of property:
| document | |
| window | |
| window | |
| frame | |
| navigator | |
| form | |
| ... |
Objects are provided with either methods or properties. Properties are formulated as attribute-value pairs.
| onLoad | if object (e.g. page) finishes loading |
| onAbort | if object (e.g. page) loading stops |
| onUnload | if object (e.g. window) is left |
| onError | if input, output or programming error |
| onSubmit | if form is submitted |
| onClick | if mouse clicks on object |
| onSelect | if mouse selects item in object |
| onFocus | if mouse activates object |
| onChange | if mouse changes object |
| onBlur | if mouse quits object |
| onMouseOver | if mouse moves over object |
| onMouseOut | if mouse moves off object |
alert("Hello World!") document.write("This is a message!")
Simple input (button click) and output (write and alert) events: this demo program uses the following code:
<HTML>
<HEAD>
<TITLE>Hello World!</TITLE>
<SCRIPT LANGUAGE=JAVASCRIPT>
function writeThis(message){
document.write(message)
}
function helloThere(message){
alert('Welcome to ' + message)
}
function getGoogle(message){
helloThere(message)
window.location="http://www.google.com/"
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR=PINK>
<SCRIPT LANGUAGE=JAVASCRIPT>
writeThis("Hi there, welcome to the test ...")
</SCRIPT>
<FORM>
<INPUT
TYPE="button"
VALUE="Earth"
onClick="helloThere('the Earth')"
>
<INPUT
TYPE="button"
VALUE="Venus"
onClick="helloThere('Venus')"
>
<INPUT
TYPE="button"
VALUE="Mars"
onClick="helloThere('Mars')"
>
<INPUT
TYPE="button"
VALUE="Google"
onClick="getGoogle('Google')"
>
</FORM>
</BODY>
</HTML>
You will need to form groups for these tasks: