Lecture: JavaScript I
JavaScript Introduction
References: Stein, L.D. 'How To Set Up and Maintain a Web Site'
2nd edn, Addison Wesley 1997, Chpt10.
Flanagan, D. 'JavaScript, The Definitive Guide'
2nd edn, O'Reilly & Associates, Inc.
- It is essential that one or both of these texts, or some other reference
(eg. the WWW) be consulted on this topic.
- This page is a summary only of a few
important JavaScript language features after Stein. It is not intended to be a
comprehensive explanation of JavaScript.
JavaScript is not Java!
- Java is a complete programming language which may be used generally
as well as on the Web.
- JavaScript code is embedded in an HTML document.
- JavaScript is a scripting language designed to be executed by the
Netscape browser when it receives an HTML document containing code.
- JavaScript runs on the client machine and so it is not affected by slow
Internet connections.
- JavaScript can read and write HTML documents that the browser
has open including the document in which the script itself resides.
- JavaScript has access to some of the browser's functions such
as the forward & backward buttons.
- JavaScript is suitable for constructing intelligent HTML documents
(eg. self-checking fill-out forms) and dynamically created HTML pages.
- If you need to go beyond the bounds of HTML, JavaScript won't help you,
look at Java instead.
HAL, the starship's computer is behaving strangely. He has killed all the ship's
crew except for you. In an emergency (like now) hit this panic button.
There, now that's not so bad is it? You just asked your browser to execute some JavaScript.
Implementing the Panic Button using JavaScript.
- The source <HEAD> of this document (have a look!) contains some code.
<SCRIPT>
function daisy()
{
alert("Daisy, Daisy, give me your answer do.\n" +
"I am crazy, all for the love of you.\n" +
"Will you marry me Dave?");
}
</SCRIPT>
|
- <SCRIPT> & </SCRIPT> tags identify their contents as JavaScript.
- A function named daisy is defined.
- Function daisy calls Netscape's built in 'alert' dialogue box.
- The source <BODY> of this document (have a look too!) contains some code.
<FORM>
<INPUT TYPE="button" NAME="myButton"
VALUE="Panic Button" onClick="daisy()">
</FORM>
|
- This creates a form with a single element of TYPE button.
- When the button is clicked, a JavaScript routine (daisy!) is called.
- This is about as interesting (and as useful) as a "Hello World" programme!
Dave: Open the pod bay door HAL!
HAL: I'm sorry Dave, I can't do that.
Did you de-activate HAL? Or are you doomed to be de-activated yourself?
- The alert, prompt
and confirm dialogue boxes have all been used above.
- The document source reveals that JavaScript syntax is similar
to that of the C programming language.
Time now to have a look at the
JavaScript Syntax.
javaScript introduction |
javaScript syntax
lecture notes |
home
All material accessed from www.cs(se).monash.edu.au/~aland is
Copyright © 1994-1999
Alan Dorin.
All rights reserved.