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

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

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

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

Fundamentals of Website Development

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

Events: another simple example

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

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

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

Introduction to DHTML

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

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

CSC Javascript

DOM Primer Part 2. Contents

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

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

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

JavaScript Handling Events Page 1

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

Full file at Tutorial 2: Working with Operators and Expressions

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

Photo from DOM

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

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

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

Place User-Defined Functions in the HEAD Section

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

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

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

Introduction to JavaScript, Part 2

Installation and Configuration Manual

New Media Production Lecture 7 Javascript

Introduction to JavaScript

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

Q1. What is JavaScript?

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

Chapter 14 - Dynamic HTML: Event Model

Web Engineering (Lecture 06) JavaScript part 2

JavaScript Programming Chris Seddon

JSF - H:SELECTONEMENU

Note: Java and JavaScript are two completely different languages in both concept and design!

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

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

Name Related Elements Type Default Depr. DTD Comment

The first sample. What is JavaScript?

JSF - H:SELECTONERADIO

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

CICS 515 a Internet Programming Week 3. Mike Feeley

JSF - H:PANELGRID. JSF Tag. Rendered Output. Tag Attributes. The h:panel tag renders an HTML "table" element. Attribute & Description.

IS 242 Web Application Development I

TEXTAREA NN 2 IE 3 DOM 1

Such JavaScript Very Wow

Session 16. JavaScript Part 1. Reading

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

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

Continues the Technical Activities Originated in the WAP Forum

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

Session 6. JavaScript Part 1. Reading

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

Client vs Server Scripting

Web Development & Design Foundations with HTML5

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

JavaScript Introduction

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

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

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

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

Experience the Magic of On-the-fly Modernization. Screen Customization Guide. for Genie Version 3.0

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

Skyway Builder Web Control Guide

Web GUI Development CSE5544

DC71 INTERNET APPLICATIONS JUNE 2013

JavaScript: A Crash Course

CISC 1600 Lecture 2.4 Introduction to JavaScript

JavaScript Introduction

JavaScript. The Basics

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

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

Javascript Hierarchy Objects Object Properties Methods Event Handlers. onload onunload onblur onfocus

HTML 5 Tables and Forms

AJAX Securely by Matt Payne, CISSP

JAVASCRIPT. JavaScript is the programming language of HTML and the Web. JavaScript Java. JavaScript is interpreted by the browser.

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?

JavaScript s role on the Web

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. VBScript

Automated Article Links Identification for Web-based Online Medical Journals

KillTest *KIJGT 3WCNKV[ $GVVGT 5GTXKEG Q&A NZZV ]]] QORRZKYZ IUS =K ULLKX LXKK [VJGZK YKX\OIK LUX UTK _KGX

Controlled Assessment Task. Question 1 - Describe how this HTML code produces the form displayed in the browser.

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

EVENT-DRIVEN PROGRAMMING

Window Interface. get only ApplicationCache window.applicationcache. get only boolean window.closed

XHTML Mobile Profile. Candidate Version Feb Open Mobile Alliance OMA-TS-XHTMLMP-V1_ C

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)

About the Author. Liability

Developing for Ajax. Ajax 101. A Look Under the Hood. Bill W. Scott, Y! Ajax Evangelist.

Mouse-over Effects. Text based buttons

CITS1231 Web Technologies

Programing for Digital Media EE1707. Lecture 3 JavaScript By: A. Mousavi and P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Transcription:

LECTURE-3 Exceptions JS Events 1

EXCEPTIONS Syntax and usage Similar to Java/C++ exception handling try { // your code here catch (excptn) { // handle error // optional throw 2

EXCEPTIONS EXAMPLE <html> <head> <title> Error handling example </title> <script> function handleerror( ) { try { i = foo( ); // Calling an undefined function raises an exception return i; catch (err) { alert ("Something was wrong"); return ("Error!"); </script> </head> <body> <script type="text/javascript"> var i = handleerror(); document.write ("i: " + i); </script> </body> </html> 3

THROW Syntax throw (exception) Example try { // some code catch (error) { // handle error throw (error2) 4

THROW EXAMPLE <html> <body> <script> var x = prompt ("Enter a number between 0 and 10:",""); try { if (x > 10) throw "Err1"; else if (x < 0) throw "Err2"; catch (er) { if (er == "Err1") </script> </body> </html> alert ("Error! The value is too high"); if (er == "Err2") alert ("Error! The value is too low"); 5

EVENTS Events in Javascript something happening. Examples Web page is loaded/unloaded Mouse key clicked/double-clicked Mouse hovering over/out-of a region Any keyboard key is pressed/released An error has occurred A submit or reset button is pressed. An element gets or loses focus. Complete list of events are given at http://www.w3schools.com/jsref/jsref_events.asp 6

EVENTS ONLOAD( ) Called (if defined) when a web page is loaded. Simple Example <html> <head> <title> On Load event example </title> <script type="text/javascript"> function onloadfn( ) // Function definition { alert ("Web page finished loading"); </script> </head> <body onload="onloadfn( )">// Call it when page is loaded </body> </html> 7

EVENTS ONUNLOAD Opposite of onload Called when We go out of a web page or A web page is re-loaded. Example Same example as before Except replace onload with onunload. 8

EVENTS ONERROR Recall our example of error handling Example: onerror=handleerr // Call handleerr on errors function handleerr(msg,url,l) // msg error msg, url current URL, l line # { //Handle the error here return true or false 9

EVENTS ONSUBMIT, ONRESET onsubmit Event when a submit button is pressed. E.g., When using forms. onreset event when a reset button is pressed. Typically, used to cancel/reset the values of all fields. 10

EVENTS ONMOUSEUP, ONMOUSEDOWN, ONMOUSEOVER, ONMOUSEOUT onmousedown event when a mouse button is pressed down. onmouseup event when a mouse button is pressed up. onmouseover event when a mouse hovers over (a specific region). onmouseout event when a mouse comes out (of a specific region). 11

EVENTS ONKEYPRESS, ONKEYDOWN, ONKEYUP onkeypress Event when a key is pressed onkeydown Event when a key is pressed or held down Similar to onkeypress onkeyup Event when a key is released (after being pressed) 12

EVENTS ONCLICK, ONDBLCLICK, ONCHANGE onclick event when a mouse button is clicked ondblclick event when a button is double clicked Try to avoid onclick when ondblclick is defined 13

EVENTS ONFOCUS, ONBLUR, ONRESIZE onfocus event when an element gets focus onblur event when an element loses focus Opposite of onfocus 14

EVENTS ONRESIZE, ONCHANGE, ONABORT onresize event when a browser window is resized (changed). onchange event when the value of a field changes onabort event when loading of an image is interrupted. 15

TIMING EVENTS settimeout: execute something after a given time Syntax: var t = settimeout (code, time_in_msec); Similar to sleep Difference with sleep: Code settimeout is executed immediately, no timeout there. cleartimeout: Cancel a timeout condition Syntax: cleartimeout (t) t was the variable returned by settimeout 16