Javascript Intro1
Javascript Intro1
Introduction to JavaScript
Introduction to JavaScript
Introduction
What is it?
How does it work?
What is Java?
Learning JavaScript
JavaScript Statements
JavaScript and HTML forms
1
CSC 1020
Introduction to JavaScript
What is JavaScript?
Browsers have limited functionality
Text, images, tables, frames
JavaScript allows for interactivity
Browser/page manipulation
Reacting to user actions
A type of programming language
Easy to learn
Developed by Netscape
Now a standard exists –
www.ecma-international.org/publications/
standards/ECMA-262.HTM
2
CSC 1020
Introduction to JavaScript
What is Java?
Totally different
A full programming language
Much harder!
A compiled language
Independent of the web
Sometimes used together
3
CSC 1020
Introduction to JavaScript
Learning JavaScript
Special syntax to learn
Learn the basics and then use other people's
(lots of free sites)
Write it in a text editor, view results in browser
You need to revise your HTML
You need patience and good eyesight!
JavaScript Statements
<html>
<head><title>My Page 1</title></head>
<body>
<script language="JavaScript">
document.write('This is my first
JavaScript Page');
4
CSC 1020
Introduction to JavaScript
JavaScript Statements
<html>
<head><title>My Page</title></head>
<body>
<script language=“JavaScript">
document.write('<h1>This is my first
JavaScript Page</h1>');
</script>
HTML written
</body> inside JavaScript
</html>
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>
</p>
An Event JavaScript written
</body> inside HTML
</html>
5
CSC 1020
Introduction to JavaScript
Example Statements
<script language="JavaScript">
window.prompt('Enter your name:','');
</script> Another event
<form>
<input type="button" Value="Press"
onClick="window.alert('Hello');">
</form> Note quotes: " and '
6
CSC 1020
Introduction to JavaScript
<form name="addressform">
Name: <input name="yourname"><br />
Phone: <input name="phone"><br />
Email: <input name="email"><br />
</form>
document.addressform.yourname.value
document.addressform.phone.value
document.addressform.email.value
7
CSC 1020
Introduction to JavaScript
<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
Check your statements are on one line
Check your " and ' quotes match
Take care with capitalisation
Lay it out neatly - use tabs
Be patient