JavaScript Event Handling.

Slides:



Advertisements
Similar presentations
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
Advertisements

MSc. Publishing on WWW JavaScript. What is JavaScript? A scripting language devised by Netscape Adds functionality to web pages by: Embedding code into.
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
INTRODUCTION TO DHTML. TOPICS TO BE DISCUSSED……….  Introduction Introduction  UsesUses  ComponentsComponents  Difference between HTML and DHTMLDifference.
JS: DOM Form Form Object Form Object –The Form object represents an HTML form. –For each instance of a tag in an HTML document, a Form object is created.
Web engineering. Topic: DHTML Presented by: Shah Rukh Presented to: Sir Ahsan raza.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
JavaScript II ECT 270 Robin Burke. Outline JavaScript review Processing Syntax Events and event handling Form validation.
Lesson 19. JavaScript errors Since JavaScript is an interpreted language, syntax errors will usually cause the script to fail. Both browsers will provide.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Working with Objects Creating a Dynamic Web Page.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
DHTML - Introduction Chapter Introduction to DHTML, the DOM, JS review.
DHTML: Working with Objects Creating a Dynamic Web Page.
JavaScript - A Web Script Language Fred Durao
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
Cs332a_chapt10.ppt CS332A Advanced HTML Programming DHTML Dynamic Hypertext Markup Language A term describing a series of technologies Not a stand-a-lone.
Event JavaScript's interaction with HTML is handled through events that occur when the user or browser manipulates a page. When the page loads, that is.
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
TOPIC II Dynamic HTML Prepared by: Nimcan Cabd Cali.
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.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
INTRODUCTION JavaScript can make websites more interactive, interesting, and user-friendly.
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
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 II ECT 270 Robin Burke. Outline Functions Events and event handling Form validation.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
JavaScript and Ajax (JavaScript Dynamic HTML (DHTML)) Week 7 Web site:
CIS 375—Web App Dev II DHTML. 2 Introduction to DHTML _________ HTML is “a term used by some vendors to describe the combination of HTML, style sheets.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
Third lecture Event 27/2/2016 JavaScript Tutorial.
Servlets What is a Servlet?
Introduction to.
DHTML.
Build in Objects In JavaScript, almost "everything" is an object.
Web Basics: HTML/CSS/JavaScript What are they?
Javascript and Dynamic Web Pages: Client Side Processing
Using DHTML to Enhance Web Pages
Using JavaScript to Show an Alert
JavaScript is a programming language designed for Web pages.
W3C Web standards and Recommendations
Intro to JavaScript CS 1150 Spring 2017.
Web Development & Design Foundations with HTML5 7th Edition
JavaScript Functions.
Section 10.1 YOU WILL LEARN TO… Define scripting
14 A Brief Look at JavaScript and jQuery.
Introduction to JavaScript
JavaScript Introduction
DHTML Javascript Internet Technology.
Web Programming A different world! Three main languages/tools No Java
Your 1st Programming Assignment
DHTML Javascript Internet Technology.
Introduction to Programming the WWW I
Web Design and Development
Javascript and JQuery SRM DSC.
Introduction to DHTML, the DOM, JS review
Computer communications
Events: Changed and Input
Code Topic 9 Standard JavaScript Events Laura Friedman
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
JavaScript is a scripting language designed for Web pages by Netscape.
HTML and CSS Basics.
Web Programming and Design
Presentation transcript:

JavaScript Event Handling

Java script Event Handling

What is an Event  JavaScript's interaction with HTML is handled through events When the page loads, it is called an event. When the user clicks a button, that click too is an event. Other examples include events like pressing any key, closing a window, resizing a window, etc. HTML events are "things" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can "react" on these events.

JavaScript lets you execute code when events are detected. HTML allows event handler attributes, with JavaScript code, to be added to HTML elements. Syntax <some-HTML-element some-event='some JavaScript'> Example <button onclick="document.getElementById('demo').innerHTML = Date()">The time is?</button>

onsubmit Event type onsubmit is an event that occurs when you try to submit a form. You can put your form validation against this event type. <html> <head> <script type="text/javascript"> <!-- function validation() { all validation goes here ......... return either true or false } //--> </script> </head> <body> <form method="POST" action="t.cgi" onsubmit="return validate()"> ....... <input type="submit" value="Submit" /> </form> </body> </html>

DHTML with JavaScript

DHTML (Dynamic HyperText Markup Language)  It is a new way of looking at and controlling the standard HTML codes and commands collection of technologies that are used to create interactive and animated web sites allows the pages to change at any time, without returning to the Web server first DHTML is NOT a language. DHTML is a TERM describing the art of making dynamic and interactive web pages. DHTML combines HTML, JavaScript, DOM, and CSS. HTML 4 The W3C HTML 4 standard has rich support for dynamic content: HTML supports JavaScript HTML supports the Document Object Model (DOM) HTML supports HTML Events HTML supports Cascading Style Sheets (CSS) DHTML is about using these features to create dynamic and interactive web pages.

write the dynamic html on the html document <body> <h1 id="header">Old Header</h1> <script type="text/javascript"> document.getElementById("header").innerHTML="New Header"; </script> </body> </html> <html> <body> <img id="image" src="Desert.jpg"> <script type="text/javascript"> document.getElementById("image").src="Koala.jpg"; </script> </body> </html>

JavaScript, DOM, and CSS With HTML 4, JavaScript and the HTML DOM can be used to change the style any HTML element. To change the style the current HTML element, use the statement: style.property=new style or more correctly: this.style.property=new style <html> <body> <h1 id="header" onclick="this.style.color='red'">Click Me!</h1> <p>If you click the header above, it turns red.</p> </body> </html>

To change the style of a specific HTML element, use the statement: document.getElementById(element_id).style.property=new style <html> <body> <h1 onclick="document.getElementById('p1').style.color='red'">Click Me!</h1> <p id="p1">If you click the header above, I turn red.</p> </body> </html>