Event-Driven Programming Chapter 19. 2 Page Section: Section or division of an HTML page Generic block element Example: What's the difference between.

Slides:



Advertisements
Similar presentations
Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
Advertisements

HTML – A Brief introduction Title of page This is my first homepage. This text is bold  The first tag in your HTML document is. This tag tells your browser.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
The Web Warrior Guide to Web Design Technologies
Capturing user input: Using HTML FORMs User input Up till now, our HTML documents have all been directed at outputting information to the user However,
JavaScript- Introduction. What it is and what it does? What it is? It is NOT Java It is NOT Server-side programming Users can see code It is a client-side.
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.
Tutorial 13 Working with Objects and Styles. XP Objectives Learn about objects and the document object model Reference documents objects by ID, name,
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
More Event-Driven Programming Chapter Exercise Make a button whose label toggles between "on" and "off".
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.,
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.
KRAD makes it easy to handle HTML events in your webpage. Kuali University: Apply Now Lab 6: Fun with HTML Events Lab Objectives HTML Events – what are.
Event-driven Programming
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JavaScript Part 1.
JavaScript Part 1.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
SERVER web page repository WEB PAGE instructions stores information and instructions BROWSER retrieves web page and follows instructions Server Web Server.
Working with Cascading Style Sheets (CSS) Module 2: HTML Basics LESSON 5.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
PHP Form Introduction Getting User Information Text Input.
Button and Textbox. Input  Input objects are used to obtain input from the user viewing the webpage. They allow the user to interact with the Web. 
SERVER web page repository WEB PAGE instructions stores information and instructions BROWSER retrieves web page and follows instructions Server Web Server.
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Dialog boxes in JavaScript Events in JavaScript – What are they – “Which events are there?” – “How do I register event handlers to an HTML element?” –
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
JavaScript, Fourth Edition
Cascading Style Sheets
Event Handling © Copyright 2014, Fred McClurg All Rights Reserved.
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
JavaScript Challenges Answers for challenges
CIS 375—Web App Dev II JavaScript I. 2 Introduction to DTD JavaScript is a scripting language developed by ________. A scripting language is a lightweight.
 Scripts that execute in response to some event  User clicking on something  Script does NOT execute as part of page loading  DOM facilities like.
CSS Cascading Style Sheets A very brief introduction CSS, Cascading Style Sheets1.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Event Handling (the right way). A Simple Web Page Events - Summary The web page looks like this:
Review of HTML and CSS A (very) brief review of some key fundamentals to be aware of in IT-238.
Understanding JavaScript and Coding Essentials Lesson 8.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
HTML Tutorial. What is HTML HTML is a markup language for describing web documents (web pages) HTML documents are described by HTML tags Each HTML tag.
Changing CSS Styles via JavaScript No readings?. 2 Review? You can change the CSS styling of an element with JavaScript Syntax is similar to accessing.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
CSS Introductions. Objectives To take control of the appearance of a Web site by creating style sheets. To use a style sheet to give all the pages of.
Third lecture Event 27/2/2016 JavaScript Tutorial.
XHTML Forms.
Introduction to.
Week 3: Introduction to Javascript
Retrieving information from forms
Introduction to JavaScript
JavaScript Introduction
DHTML Javascript Internet Technology.
A second look at JavaScript
Event Driven Programming & User Defined Functions
DHTML Javascript Internet Technology.
Functions, Regular expressions and Events
Training & Development
Introduction to JavaScript
Web Programming and Design
Retrieving information from forms
Presentation transcript:

Event-Driven Programming Chapter 19

2 Page Section: Section or division of an HTML page Generic block element Example: What's the difference between and ?  Use for paragraphs of text. Use as a generic container for everything else. Look at me!

3 Text Field: Attribute type must be set to "text" Example: Name:

4 Button: Attribute type must be set to "button" Attribute value determines label of button Example:

5 Event-Driven Programming event-driven programming: programming paradigm in which the flow of the program is determined by events (e.g. mouse clicks, key presses) event handler: function that is called when a particular event occurs

6 Button Click Event Handler Set the onclick attribute to a function call Function must be declared in JavaScript file Example: Example event handler: function myFunction() { alert("Hello, world!"); }

7 Reading User Input Imagine the following web page with a text box to type your name: Clicking the button results in a popup box: The JavaScript function handling the click event needs access to the text field.

8 Recall: HTML Element

9 Identifying HTML Elements Any HTML element can be given an ID via the id attribute ID's on an HTML page should be unique Example: Name:

10 Accessing HTML Elements In JavaScript In JavaScript, you can access specific HTML elements by using a pre-defined variable called document and requesting the element by ID. Accessing an HTML element by ID, general syntax: document.getElementById(" ") Example: document.getElementById("name")

11 Accessing Attributes Of HTML Elements Once you have access to a particular HTML element, you can access all its attributes using the "dot" operator. Accessing an element's attribute, general syntax: document.getElementById(" "). Example: document.getElementById("name").value (text fields store the user input in the value attribute)

12 Previous Example HTML snippet JavaScript file Name: function welcome() { var name = document.getElementById("name").value; alert("Hi, " + name + "!"); }

13 Example HTML snippet Name: Age:

14 Example JavaScript file function checkAge() { var userName = document.getElementById("name").value; var age = document.getElementById("age").value; if (age < 21) { alert(userName + ", you can't drink!"); } else { alert("Hi " + userName + ", drink away!"); }

15 Changing Attribute Values Can also change the values of attributes HTML snippet JavaScript file Name: function welcome() { var name = document.getElementById("name").value; alert(name + ", I don't like your name. You are now Bob."); document.getElementById("name").value = "Bob"; alert("Hi Bob!"); }

16 Accessing CSS Properties Accessing CSS properties, general syntax: document.getElementById(" ").style. Property names in JavaScript are identical to those in CSS, but with namesLikeThis instead of names-like-this  Examples: backgroundColor instead of background-color fontFamily instead of font-family Example: document.getElementById("name").style.backgroundColor = "yellow";

17 Additional Events The XHTML 1.0 Strict Reference has a listing of all HTML elements and their attributes. Attributes whose names begin with on (like onclick ) can be set to event handlers. 