Académique Documents
Professionnel Documents
Culture Documents
1. DOCUMENT OBJECT
MODEL (DOM)
Window
Document
anchor
link
Form
textbox
textarea
radiobutton
checkbox
select
button
2. Definition (DOM):
The Document Object Model is a platformand language-neutral interface that will allow programs
and scripts to dynamically access and update the
content, structure and style of documents. The document
can be further processed and the results of that
processing can be incorporated back into the presented
page.
3. JavaScript:
An Object-oriented Script
JavaScript makes available a lot of predefined
ipt
Object
Description
Document
Window
History
4. KEY LANGUAGE
COMPONENTS
Objects
5. JAVASCRIPT ARRAYS
Arrays are predefined JavaScript objects.
An array must be declared before it is used.
-- arrname= new Array (Array length);
-- arrname1= new Array();
6. FUNCTIONS
A function is a definition of a set of deferred
actions. Functions are invoked by event
handlers or by statements elsewhere in the
script. Whenever possible, good functions are
designed for reuse in other documents. They
can become building blocks you use over and
over again.
A script that is sectioned off as a separate
piece of code and given a name. Using this
name, another script can call this script to
execute at any time and as often as it needs to.
Creating Functions
Calling Functions
<html><head>
<title>CE3101 demo</title>
<script type="text/javascript">
<!-function calculateValues() {
num1 = parseFloat(document.forms[0].Number1.value)
num2 = parseFloat(document.forms[0].Number2.value)
result = num1 * num2
alert(result);
}
//-->
</script></head>
<body>
<h1>Multiply the two numbers...</h1>
<form name="form1" method="POST">
<pre>
First Number: <input type="text" size="5" maxlength="5"
name="Number1">
</pre>
<pre>
Second Number: <input type="text" size="5"
maxlength="5" name="Number2">
</pre>
<p>
<input type="button" name="WizButton" value="Multiply"
onclick="calculateValues()">
</p>
</form>
</body></html>
FUNCTION PARAMETERS
Any call to a function, including one that comes from
VARIABLE SCOPE
Speaking of variables, its time to distinguish
VARIABLE SCOPE
Therefore, when you initialize a variable as a global
<HTML>
<HEAD>
<SCRIPT LANGUAGE=JavaScript>
var aBoy = Charlie Brown // global
var hisDog = Snoopy // global
function demo() {
// using improper design to demonstrate a point
var hisDog = Gromit // local version of hisDog
var output = hisDog + does not belong to + aBoy +
.<BR>
document.write(output)
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE=JavaScript>
demo() // runs as document loads
document.write(hisDog + belongs to + aBoy + .)
</SCRIPT>
</BODY>
</HTML>
7. WINDOW OBJECT
At the very top of the document object hierarchy is the
window object.
This object gains that exalted spot in the object food
chain because it is the master container for all content
you view in the Web browser.
As long as a browser window is openeven if no
document is loaded in the windowthe window object is
defined in the current model in memory.
In addition to the content part of the window where
documents go, a windows sphere of influence includes
the dimensions of the window and all of the stuff that
surrounds the content area.
Attributes of window
window.status property
The status bar at the bottom of the browser window
normally displays the URL of a link when you roll the
mouse pointer atop it.
Other messages also appear in that space during
document loading, Java applet initialization, and the
like.
However, you can use JavaScript to display your own
messages in the status bar at times that may be
beneficial to your users.
window.alert() method
window.confirm() method
window.prompt() method