introduction to javascript. introduction what is it? how does it work? what is java? learning...

16
Introduction to JavaScript

Upload: stephany-pope

Post on 19-Jan-2018

219 views

Category:

Documents


0 download

DESCRIPTION

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 – standards/ECMA-262.HTM

TRANSCRIPT

Page 1: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

Introduction to JavaScript

Page 2: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

IntroductionWhat is it?How does it work?What is Java?Learning JavaScript

JavaScript Statements JavaScript and HTML forms

Page 3: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

What is JavaScript?Browsers have limited functionality

Text, images, tables, framesJavaScript allows for interactivityBrowser/page manipulation

Reacting to user actionsA type of programming language

Easy to learn Developed by Netscape Now a standard exists – www.ecma-international.org/publications/standards/ECMA-262.HTM

Page 4: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

JavaScript Allows InteractivityImprove appearance

Especially graphics Visual feedback

Site navigationPerform calculationsValidation of inputOther technologies

javascript.internet.com

Page 5: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

How Does It Work?Embedded within HTML page

View sourceExecutes on client

Fast, no connection needed once loadedSimple programming statements combined with

HTML tagsInterpreted (not compiled)

No special tools required

Page 6: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

What is Java?Totally differentA full programming languageMuch harder!A compiled languageIndependent of the webSometimes used together

Page 7: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

Learning JavaScriptSpecial syntax to learnLearn the basics and then use other people's

(lots of free sites)Write it in a text editor, view results in browserYou need to revise your HTML You need patience and good eyesight!

Page 8: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

JavaScript Statements<html><head><title>My Page</title></head><body><script language="JavaScript">

document.write('This is my first JavaScript Page');

</script></body></html>

Note the symbol for line continuation

Page 9: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

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 writteninside JavaScript

Page 10: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

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></body></html>

JavaScript writteninside HTML

An Event

Page 11: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

Example Statements<script language="JavaScript">window.prompt('Enter your name:','');</script>

<form><input type="button" Value="Press" onClick="window.alert('Hello');">

</form>

Another event

Note quotes: " and '

Page 12: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

HTML Forms and JavaScriptJavaScript is very good at processing user input

in the web browserHTML <form> elements receive inputForms and form elements have unique names

Each unique element can be identified Uses JavaScript Document Object Model (DOM)

Page 13: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

Naming Form Elements in HTML

<form name="addressform">Name: <input name="yourname"><br />Phone: <input name="phone"><br />Email: <input name="email"><br /></form>

Page 14: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

Forms and JavaScriptdocument.formname.elementname.valueThus:

document.addressform.yourname.valuedocument.addressform.phone.valuedocument.addressform.email.value

Page 15: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

Using Form DataPersonalising an alert box

<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>

Page 16: Introduction to JavaScript. Introduction What is it? How does it work? What is Java? Learning JavaScript JavaScript Statements JavaScript and HTML forms

TipsCheck your statements are on one lineCheck your " and ' quotes matchTake care with capitalisationLay it out neatly - use tabsRemember in the workbook denotes a

continuing lineBe patient

Presentation slides adapted from scom.hud.ac.uk/scomsjw/Web%20Authoring%20Module/Lecture%20Slides/ introjs.ppt