Beruflich Dokumente
Kultur Dokumente
to JavaScript
IT 112
History
First web scripting language called
LiveScript
Developed in 10 days in May 1995
by Brendan Eich, then working
at Netscape and now of Mozilla
JavaScript was not always known as
JavaScript: the original name was
Mocha, a name chosen by Marc
Andreessen, founder of Netscape.
JavaScript
History
In parallel with this, Sun was developing
Java
Netscape and Sun got together and
realized that many of the specifications
for Java could apply to LiveScript
Result is JavaScript
JavaScript
A server-side language
is one that runs on the
Web server. Examples:
PHP, Python
To maintain data
shared among
applications or clients
To maintain information
during client accesses
To access a database
To access server files
To call server C
libraries
To customize Java
applets
4
What is JavaScript?
Browsers have limited functionality
Text, images, tables, frames
Site navigation
Perform calculations
Validation of input
Other technologies
javascript.internet.com
Executes on client
Fast, no connection needed once loaded
Java vs JavaScript
In reality, Java and JavaScript are
unrelated
10
JavaScript
11
What is Java?
Totally different
A full programming language
Much harder!
A compiled language
Independent of the web
Sometimes used together
JavaScript
Object Oriented
Objects have
Qualities or attributes
Things they can do
Object Examples
Object
Computer
Disk Drive
Attribute
Things it can do
Brand name
Model Name
Processor Type
Processor Speed
Disk Drive
Brand name
Model name
Storage capacity
Transfer rate
Access time
Boot up
Run an application
Perform math calculations
Shut down
Store information
Retrieve information
Delete information
Fundamental Concepts
Objects: The nouns of the language
Instances: incarnations of objects
Properties: attributes or state of objects
Methods: The verbs of the language
that define the behaviors of objects
Events and Events Handlers
JavaScript Variables
Variables: containers for data
All variables have
Name
Type JavaScript is loosely typed
Value or null
To declare a variable
var variablename
</script>
Attributes
Ttype, SRC
HTML Comments
<!-- All of your comments here -->
JavaScript Statements
<html>
<head><title>My Page</title></head>
<body>
<script language="JavaScript">
document.write('This is my first
JavaScript Page');
Note the symbol for
line continuation
</script>
</body>
</html>
JavaScript Statements
<html>
<head><title>My Page</title></head>
<body>
<script language=JavaScript">
document.write('<h1>This is my first
JavaScript Page</h1>');
</script>
</body>
</html>
HTML written
inside JavaScript
JavaScript Statements
<html>
<head><title>My Page</title></head>
<body>
<p>
<a href="myfile.html">My Page</a>
<br />
<a href="myfile.html"
onMouseover="window.alert('Hello');" >
My Page</A>
JavaScript written
An Event
</p>
inside HTML
</body>
</html>
Example Statements
<script language="JavaScript">
window.prompt('Enter your
name:','');
Another event
</script>
<form>
<input type="button" Value="Press"
onClick="window.alert('Hello');"
Note quotes: " and '
>
</form>
Hello, World!
Typically, in any programming
language, the first example you learn
displays Hello, World!
We are going to take a look at a Hello
World example and then examine all of
its parts.
27
28
29
<script type="text/javascript">
.
.
.
</script>
30
<form name="alertform">
Enter your name:
<input type="text" name="yourname">
<input type="button" value= "Go"
onClick="window.alert('Hello ' +
document.alertform.yourname.value);">
</form>
Tips
38