CISH-6510 Web Application Design and Development. Overview of JavaScript. Overview

Similar documents
LECTURE-3. Exceptions JS Events. CS3101: Programming Languages: Javascript Ramana Isukapalli

Fundamentals of Website Development

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

LECTURE-2. Functions review HTML Forms. Arrays Exceptions Events. CS3101: Scripting Languages: Javascript Ramana Isukapalli

JAVASCRIPT BASICS. Handling Events In JavaScript. In programing, event-driven programming could be a programming

1$ 5 ! $ 6 4 * Source: 0 "!*! 0! * 8 97 ?!$ 5 0 *! 4! $ 0 : * ' () 7;7 7<7

Key features. Nothing to do with java It is the Client-side scripting language Designed to add interactivity to HTML pages

Events: another simple example

Introduction to DHTML

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

HTML User Interface Controls. Interactive HTML user interfaces. Document Object Model (DOM)

Want to add cool effects like rollovers and pop-up windows?

JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore

Place User-Defined Functions in the HEAD Section

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) What is JavaScript?

CSC Javascript

710 Index Attributes, 127 action attribute, 263 assigning, bottom attribute, domain name attribute, 481 expiration date attribute, 480 8

Q1. What is JavaScript?

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

New Media Production Lecture 7 Javascript

Session 16. JavaScript Part 1. Reading

The first sample. What is JavaScript?

CSS The web browser uses its own resources, and eases the burden on the server. It has fewer features than server side scripting.

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

Dynamic Web Pages - Integrating JavaScript into a SAS Web Application Caroline Bahler, ASG, Inc.

By the end of this section of the practical, the students should be able to:

Introduction to JavaScript, Part 2

By the end of this section of the practical, the students should be able to:

Session 6. JavaScript Part 1. Reading

JavaScript Handling Events Page 1

Beijing , China. Keywords: Web system, XSS vulnerability, Filtering mechanisms, Vulnerability scanning.

DOM Primer Part 2. Contents

<form>. input elements. </form>

Lecture 14. Introduction to JavaScript. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Web Development & Design Foundations with HTML5, 8 th Edition Instructor Materials Chapter 14 Test Bank

Introduction to JavaScript

Javascript. A key was pressed OR released. A key was released. A mouse button was pressed.

Web Development & Design Foundations with HTML5

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

3Lesson 3: Functions, Methods and Events in JavaScript Objectives

Full file at Tutorial 2: Working with Operators and Expressions

Installation and Configuration Manual

A Balanced Introduction to Computer Science, 3/E

Name Related Elements Type Default Depr. DTD Comment

Canvas & Brush Reference. Source: stock.xchng, Maarten Uilenbroek

JavaScript Programming Chris Seddon

UNIT 3 SECTION 1 Answer the following questions Q.1: What is an editor? editor editor Q.2: What do you understand by a web browser?

Client-Side Web Programming. Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University

Client vs Server Scripting

INTRODUCTION TO WEB DEVELOPMENT AND HTML. Lecture 15: JavaScript loops, Objects, Events - Spring 2011

JavaScript is described in detail in many books on the subject, and there is excellent tutorial material at

INTRODUCTION TO WEB DEVELOPMENT AND HTML. Lecture 13: Intro to JavaScript - Spring 2011

JavaScript!= Java. Intro to JavaScript. What is JavaScript? Intro to JavaScript 4/17/2013 INTRODUCTION TO WEB DEVELOPMENT AND HTML

link document.getelementbyid("coffee").style.borderwidth = "0px" document.getelementbyid("tea").style.borderwidth = "10px"

Web Programming/Scripting: JavaScript

CITS1231 Web Technologies. JavaScript

CHAPTER 6 JAVASCRIPT PART 1

Chapter 14 - Dynamic HTML: Event Model

Continues the Technical Activities Originated in the WAP Forum

So don t copy files or photocopy - Share! Share these FREE Courses! End User License Agreement Use of this package is governed by the following terms:

JavaScript s role on the Web

Outline. Lecture 4: Document Object Model (DOM) What is DOM Traversal and Modification Events and Event Handling

COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts

UNIT - III. Every element in a document tree refers to a Node object. Some nodes of the tree are

Digitizing Sound and Images III Storing Bits

CITS3403 Agile Web Development Semester 1, 2018

a.) All main headings should be italicized. h1 {font-style: italic;} Use an ordinary selector. HTML will need no alteration.

CITS1231 Web Technologies

Javascript Lecture 23

JSF - H:INPUTSECRET. Class name of a validator that s created and attached to a component

Photo from DOM

JavaScript. Why JavaScript? Registration form. Online calculator. IT Engineering I Instructor: Ali B. Hashemi. Interaction

Dynamic HTML becomes HTML5. HTML Forms and Server Processing. Form Submission to Web Server. DHTML - Mouse Events. CMST385: Slide Set 8: Forms

5.4 JavaScript Objects and Methods

AJAX Securely by Matt Payne, CISSP

CGS 3066: Spring 2015 JavaScript Reference

About the Author. Liability

This tutorial has been designed for beginners in HTML5 to make them understand the basicto-advanced

TEXTAREA NN 2 IE 3 DOM 1

Netscape Introduction to the JavaScript Language

CS 5450 HTTP. Vitaly Shmatikov

JavaScript Introduction

Outline. Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages

Chapter4: HTML Table and Script page, HTML5 new forms. Asst. Prof. Dr. Supakit Nootyaskool Information Technology, KMITL

Notes on JavaScript (aka ECMAScript) and the DOM

JavaScript: Introduction, Types

Then there are methods ; each method describes an action that can be done to (or with) the object.

CSC 551: Web Programming. Spring 2004

JS Tutorial 3: InnerHTML Note: this part is in last week s tutorial as well, but will be included in this week s lab

IS 242 Web Application Development I

HTML 5 Tables and Forms

HTML 5 and CSS 3, Illustrated Complete. Unit L: Programming Web Pages with JavaScript

Phụ lục A. Sơ đồ các đối tượng trong trình duyệt


JavaScript. Asst. Prof. Dr. Kanda Saikaew Dept. of Computer Engineering Khon Kaen University

CISC 1600 Lecture 2.4 Introduction to JavaScript

Client-side Processing

What Is JavaScript? A scripting language based on an object-orientated programming philosophy.

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

Lesson 5: Introduction to Events

Transcription:

CISH-6510 Web Application Design and Development Overview of JavaScript Overview What is JavaScript? History Uses of JavaScript Location of Code Simple Alert Example Events Events Example Color Example 2 1

What is JavaScript? Language used for adding dynamism to Web pages. Loosely typed: Variables not typed. Object-based: based: Limited support for inheritance. Interpreted: Interpreter built into browsers. Modeled after C++. Similar syntax 3 What is JavaScript? JavaScript can: Put dynamic text into an HTML page. React to events. E.g. when a user clicks on an HTML element Read and write HTML elements. Be used to validate data. Saves network traffic and server-side side processing 4 2

History JavaScript created in 1995 by Brendan Eich of Netscape. First used in Netscape 2.0. Originally called LiveScript LiveScript. Changed to JavaScript to ride popularity of Java. 1997 European Computer Manufacturers Association (ECMA) released ECMA-262 standard. Based on JavaScript 1.1 5 JS Ver. ECMAS Version NN IE 1.0 2.0x 3.0x 1.1 Version 1 3.0x 3.02x 1.2 1.3 Not compat. Version 2 4.0x-4.05 4.05 4.07-4.7x 4.7x 4.0x 5.0x- 5.1x 1.4 Version 3 5.0 5.5x 1.5 Version 4 6.0x-7.0x 6.0x 6 3

History JavaScript 2.0 is in the works. www.mozilla.org Under development as of spring 2004 Closely matches the ECMAScript Edition 4 standard. http://www.ecma-international.org 7 Uses of JavaScript Dynamism takes three forms: 1. Events: Allows you to monitor events and change positioning or content based on events. 2. Dynamic positioning: Can tell the browser where to place content without using tables. 3. Dynamic content: Allows dynamic updating of data at specified time intervals. 8 4

Location of Code JavaScript may be three places: 1. In the <head> element. Place scripts to be called or when event is triggered here Ensures script is loaded before called <html> <head> <script type="text/javascript > script statements </script> </head> 9 Location of Code 2. In the <body> element. Place scripts to be executed when the page loads here Script generates some or all of the content of the page <body> <script type="text/javascript"> script statements </script> </body> 10 5

Location of Code 3. External to the HTML file. Maximizes reuse across pages <head> <script src= myfile.js"> </script> </head> Script could be in <head> or <body>. External script should not contain <script> tag. 11 Simple Alert Example Try the example at: http://www.rh.edu/~heidic/ webtech/examples/javascript/ simple.html Simple JavaScript Example using Alert Click on the button greetings 12 6

Simple Alert Example <html> <head> <title> Simple JavaScript alert button example. </title> <script language= JavaScript type= text/javascript > function mywelcome () { alert("welcome to Heidi Ellis' simple JavaScript page.");} </script> 13 Simple Alert Example </head> <body> <h1>simple JavaScript Example using Alert. </h1> <script> document.writeln( "Click on the button.") </script> 14 7

Simple Alert Example <form> <input type="button" name="welcome" value="greetings" onclick="mywelcome()"> </form> </body> </html> 15 Events One of the primary uses of JavaScript is to make Web pages interactive. Responsive to user actions JavaScript provides event handlers. Execute segment of code based on events occurring within the application E.g., onload or onclick Handlers associated with elements. Not all elements support all event handlers. 16 8

Events <input type="button" name="clickme" value="click Here" onclick= "window.status='thanks'; return true;"> 17 Events Event handlers can be categorized into interactive and non-interactive. Interactive: Depends on a user action. E.g., onclick Non-interactive: Non-user event. E.g., onload 18 9

Events onabort: : Image loading is interrupted. onblur: : Element loses input focus. onchange: : User selects or deselects item. onclick: : User clicks once. ondragdrop: onerror: : Image doesn t load properly. 19 Events onfocus: : Element is given input focus. onkeypress: onkeyup: onload: onmousedown: onmouseover: onmouseout: onmouseup: 20 10

Events onmove: : User or JavaScript moves window. onreset: : User clicks reset button. onresize: : User resizes window. onselect: : User selects text in text or textarea. onsubmit: : User clicks submit button. onunload: : User exits document. Gatescript has event reference page: http://www.gatescript.com www.gatescript.com/ events.html 21 Events Supporting Events 1. Give the target HTML element a name attribute. <input type="text" name="price" /> 2. Give activating HTML element event attribute that calls function. <input type="submit" value="calculate total." onclick="calctotal()"/> 22 11

Events Supporting Events 3. Write the JavaScript function to modify the DOM element with the name attribute. Try the Event page JavaScript example: http://www.rh.edu/~heidic/ webtech/examples/javascript/ events.html 23 Events Example Simple Example to Show the use of Events Enter a price... Price of item: 10 Quantity purchased: 12 The total is: 120 24 12

Events Example <html> <head> <title> JavaScript Test </title> <script language="javascript" type="text/javascript"> 25 Events Example function calctotal() { tot = document.totalform. price.value * document.totalform.qty.value; document.totalform.total.value = tot; } </script> 26 13

Events Example </head> <body bgcolor="papayawhip"> <h1>simple Example to Show the use of Events</h1> <p>enter a price and move cursor out of box. The new total will be calculated automatically. 27 Events Example </p> <form name="totalform"> Price of item: <input type="text" name="price" onmouseout="calctotal()" /> <br> Quantity purchased: 28 14

Events Example <input type="text" name="qty" onmouseout="calctotal()" /> <br> <br> The total is: <input type="text" name="total" /> <br> 29 Events Example </form> </body> </html> 30 15

Color Example Try the Color example JavaScript: http://www.rh.edu/~heidic www.rh.edu/~heidic/ webtech/examples/javascript/ prop.html <html> <head> <title> Simple JavaScript document properties example. </title> </head> 31 Color Example <body bgcolor="white"> <script language="javascript" type="text/javascript"> document.bgcolor="red"; alert("press button for another color"); document.bgcolor="blue"; alert("press button for another color"); 32 16

Color Example document.bgcolor="cyan"; alert("press button for another color"); document.bgcolor="indigo"; alert("press button for a different title"); document.title= "New Document Title"; </script> 33 Color Example <center> <h1> Color Play!! </h1> </center> </body> </html> 34 17

Workshop 1 Create a small Web page that prompts the user to enter their name. Write a JavaScript function that pops up an alert when the user has entered their name. Advanced: Display the user s name in the alert. 35 18