Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.

Slides:



Advertisements
Similar presentations
Chapter 08: Adding Adding Interactivity Interactivity With With Behaviors Behaviors By Bill Bennett Associate Professor MSJC CIS MVC.
Advertisements

Introducing JavaScript
Essentials for Design JavaScript Level One Michael Brooks
The Web Warrior Guide to Web Design Technologies
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
Lecture 3B: Client-Side Scripting IT 202—Internet Applications Based on notes developed by Morgan Benton.
20-Jun-15 JavaScript and HTML Simple Event Handling.
Tutorial 10 Programming with JavaScript
Computer Science 103 Chapter 4 Advanced JavaScript.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript - 1
Introduction To JavaScript What JavaScript Is: a general purpose scripting language that allows a static page to interact with users and respond to events.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Web Programming Material From Greenlaw/Hepp, In-line/On-line: Fundamentals of the Internet and the World Wide Web 1 Introduction The JavaScript Programming.
1 Events Lect 8. 2 Event-driven Pages one popular feature of the Web is its interactive nature e.g., you click on buttons to make windows appear e.g.,
CP476 Internet Computing JavaScript and HTML1 1.JavaScript Execution Environment The JavaScript Window object represents the window in which the browser.
Javascript and the Web Whys and Hows of Javascript.
4.1 JavaScript Introduction
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
JavaScript - a Brief Introduction Anupriya. What is JavaScript Object based (not object oriented) programming language –very limited object creation –a.
Server vs Client-side validation. JavaScript JavaScript is an object-based language. JavaScript is based on manipulating objects by modifying an object’s.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
JavaScript II ECT 270 Robin Burke. Outline JavaScript review Processing Syntax Events and event handling Form validation.
Chapter 5 JavaScript and HTML Documents. © 2006 Pearson Addison-Wesley. All rights reserved JavaScript Execution Environment - The JavaScript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JavaScript Part 1.
JavaScript 1. What is JavaScript? JavaScript allows web authors to create dynamic pages that react to user interaction. It is an Object-based because.
Lesson 19. JavaScript errors Since JavaScript is an interpreted language, syntax errors will usually cause the script to fail. Both browsers will provide.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1 JavaScript in Context. Server-Side Programming.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 14 JavaScript.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
JavaScript - A Web Script Language Fred Durao
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
44238: Dynamic Web-site Development Client Side Programming Ian Perry Room:C48 Extension:7287
Cs332a_chapt10.ppt CS332A Advanced HTML Programming DHTML Dynamic Hypertext Markup Language A term describing a series of technologies Not a stand-a-lone.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
Introduction To JavaScript. Putting it Together (page 11) All javascript must go in-between the script tags. All javascript must go in-between the script.
JavaScript Introduction. Slide 2 Lecture Overview JavaScript background The purpose of JavaScript A first JavaScript example Introduction to getElementById.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
Project 8: Reacting to Events Essentials for Design JavaScript Level One Michael Brooks.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
JavaScript Event Handlers. Introduction An event handler executes a segment of a code based on certain events occurring within the application, such as.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
Copyright © Terry Felke-Morris Web Development & Design Foundations with HTML5 8 th Edition CHAPTER 14 KEY CONCEPTS 1 Copyright.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
Web Development & Design Foundations with HTML5
JavaScript is a programming language designed for Web pages.
Web Development & Design Foundations with HTML5 7th Edition
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript Introduction
JavaScript Overview By Kevin Harville.
JavaScript Basics What is JavaScript?
JavaScript is a scripting language designed for Web pages by Netscape.
Presentation transcript:

Lesson13

JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.

JavaScript JavaScript was created by Netscape. JavaScript is easy to learn because its syntax is similar to that of the modern high- level languages like C, C++, and Java.

JavaScript Java and JavaScript are two separate, unrelated languages. The original name for the language was LiveScript The name JavaScript was chosen as a marketing ploy to use the name Java to attract attention.

JavaScript Microsoft created their own scripting language for use within a browser. It is called VBScript, and is based on Visual Basic. Fortunately, Microsoft also created JScript, their version of JavaScript. Internet Explorer can handle pages using either JavaScript (JScript) or VBScript.

JavaScript Jscript can be considered the same as JavaScript for practical purposes, so we can use JavaScript in both IE and Netscape. VBScript can only be used with Internet Explorer.

ECMAScript There is work underway to standardize the language, and a new name, ECMAscript, is used to refer to the standardized language. (ECMA stands for European Computer Manufacturer’s Association). This standardization will not affect current JavaScripts.

JavaScript my first script document.write("hello, world!")

The Document Object Model (DOM) The DOM provides a naming convention which allows us to refer to various parts of a web page by name. Once we can do this, we can use JavaScript to control and work with these different items. The DOM is not a part of JavaScript. It is a separate standard that allows us to use JavaScript with the different parts of an HTML page.

DOM naming conventions The DOM uses a hierarchical naming convention, like Java. We break the page up into a number of objects. We use dots to separate the different levels, from general to specific.

DOM naming conventions This is similar to specifying where someone lives by starting with the continent, then the country, then the province, then the city, then the street, then the building number, then the apartment, like this; NorthAmerica.Canada.Ontario.Toronto.AnyStreet

DOM naming conventions Some DOM objects are: –document: refers to the HTML page –window: refers to the browser window –forms: refers to the form elements in the document (e.g. text boxes, radio buttons etc.)

DOM naming conventions Some more DOM objects are: –images: refers to all the images in a document –navigator: refers to an unseen object that contains information about the browser version and type.

Events For our purposes at this time, an event is the result of an action taken by a user. Examples of user actions are; –Moving the mouse cursor over an image –Moving the mouse cursor away from an image –Clicking the mouse button –Double clicking the mouse button

Events Certain HTML tags have attributes to describe these events. These are called event handlers. The browser will take action when an event occurs, based on the value of the attribute.

Events Some common event handlers we will use are: –onMouseOver : Defines the action to take when the mouse pointer is placed over the image. –onMouseOut: Defines the action to take when the mouse pointer is moved off the image.

Events More common event handlers: –onChange: Defines an action to take when there is a change to the input field. –onBlur: Defines an action to take when focus is removed from the element.

Events More common event handlers: –onSubmit: Defines the action to take when a form has been submitted. –onLoad: Defines an action to take when a page has loaded.

JavaScript (continued) my first script <!-- hide script from old browsers document.write("hello, world!") // end hiding script from old browsers -->

JavaScript (continued) my first script <!-- hide script from old browsers /* this is an example of a long javascript comment. note the characters at the beginning and ending of the comment. this script adds the words "hello, world!" into the body area of the html page. */ document.write("hello, world!") // end hiding script from old browsers -->

JavaScript (continued) you should have javascript! <!-- hide script from old browsers window.location="jswelcome.html" // end hiding script from old browsers --> you won't get much from this site without the latest version of javascript--i suggest that you upgrade now!

JavaScript (continued) welcome to our site <a href="script04.html" onclick="window.location='jswelcome.html'; return false">welcome to our site... c'mon in!

JavaScript (continued) welcome to our site <a href="script04.html" onclick="window.location='jswelcome.html'; return false">welcome to our site... c'mon in!

JavaScript (continued) what's your browser? <!-- hide script from old browsers if (navigator.appname == "netscape") { document.write("you're running netscape navigator, a fine javascript- enabled browser.") } else { document.write("you're not running netscape navigator--maybe you should?") } // end hiding script from old browsers -->

Dynamic images (1) For our first use of DHTML, we will learn how to cause an image to change, based on the mouse position. This is commonly referred to as an image flip.

Dynamic images (2) The tag has the following attributes that we will take advantage of; –onMouseOver : Defines the action to take when the mouse pointer is placed over the image which is inside the tag. –onMouseOut: Defines the action to take when the mouse pointer is moved off the image which is inside the tag.

Dynamic images (3) We will make it so that when the user puts the mouse over a certain image, that image changes. To do this, we need to create the two different images. 1.The default image, the one the user sees first. 2.The swap image, the one that replaces the default image when the mouse is placed over it.

Dynamic images (4) The default image: The swap image:

Dynamic images (5) Start with a normal tag inside an anchor, like this; Give a name to our image

Dynamic images (6) In order to change the image on the screen, we need to be able to refer to it. We use the DOM for this, giving the complete path to the image. The DOM path to our image is document.images.image1

Dynamic images (7) Now we specify what we want to change about this image, in this case it is the src attribute (i.e. which image is being displayed) document.images.image1.src

Dynamic images (8) Next we add the onMouseOver attribute to the tag containing the image we want to change, and we use the DOM to say what image to use instead. Note the single quotes inside the double quotes.

Dynamic images (9) This works fine, but once we put the mouse over the image, it changes and stays that way. Now we want to make it so that when we move the mouse off the image, it goes back to the original image.

Dynamic images (10) Now we need to use the onMouseOut attribute to set the behaviour when the mouse cursor is moved off the image.

Dynamic images (11) We just have to change the code as follows; <a href="mouseovermouseout.html" onMouseOver="document.images.image1.src='presshere.gif'" onMouseOut="document.images.image1.src='lookatme.gif'">

JavaScript errors Since JavaScript is an interpreted language, syntax errors will usually cause the script to fail. Both browsers will provide error messages which can be very helpful in debugging JavaScript.