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.,

Slides:



Advertisements
Similar presentations
17 HTML, Scripting, and Interactivity Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and.
Advertisements

Chapter 08: Adding Adding Interactivity Interactivity With With Behaviors Behaviors By Bill Bennett Associate Professor MSJC CIS MVC.
Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
The Web Warrior Guide to Web Design Technologies
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 7 Event-Driven.
CIS101 Introduction to Computing Week 10 Spring 2004.
Computer Science 103 Chapter 4 Advanced JavaScript.
CIS101 Introduction to Computing Week 10. Agenda Your questions Final exam and final project CIS101 Student Survey Class presentations: Your Mad Libs.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
Web Programming Material From Greenlaw/Hepp, In-line/On-line: Fundamentals of the Internet and the World Wide Web 1 Introduction The JavaScript Programming.
Javascript and the Web Whys and Hows of Javascript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
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.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
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.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
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.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
1 Functions Lecfture Abstraction abstraction is the process of ignoring minutiae and focusing on the big picture in modern life, we are constantly.
JavaScript - A Web Script Language Fred Durao
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. 
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
1 JavaScript 2 JavaScript. 2 Rollovers Most web page developers first use JavaScript for rollovers A rollover is a change in the appearance of an element.
1 A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 4 JavaScript and.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
Event-Driven Programming Chapter Page Section: Section or division of an HTML page Generic block element Example: What's the difference between.
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.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Unit 10 – JavaScript Validation Instructor: Brent Presley.
HTML Overview Part 5 – JavaScript 1. Scripts 2  Scripts are used to add dynamic content to a web page.  Scripts consist of a list of commands that execute.
JavaScript Challenges Answers for challenges
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
HTML FORMS The TEXT Object Presented By: Ankit Gupta.
JavaScript Event Handlers. Introduction An event handler executes a segment of a code based on certain events occurring within the application, such as.
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.
1 Lesson 6 Introducing JavaScript HTML and JavaScript BASICS, 4 th Edition.
CSC 121 Computers and Scientific Thinking Fall Event-Driven Programming.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript 101 Lesson 6: Introduction to Functions.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
JavaScript JavaScript is a programming language that web browsers understand. You can use it to make your web pages interactive by: Responding to user.
1 JavaScript and Dynamic Web Pages Lecture 7. 2 Static vs. Dynamic Pages  A Web page uses HTML tags to identify page content and formatting information.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
Event-Driven Programming
JavaScript is a programming language designed for Web pages.
Section 17.1 Section 17.2 Add an audio file using HTML
Event Driven Programming & User Defined Functions
Chapter 4 JavaScript and Dynamic Web Pages
Events Comp 205 Fall 2017.
Chapter 6 Event-Driven Pages
Web Design and Development
JavaScript Basics What is JavaScript?
Chapter 7 Event-Driven Pages
JavaScript is a scripting language designed for Web pages by Netscape.
Introduction to Programming and JavaScript
JavaScript and Ajax (JavaScript Events)
Web Programming and Design
Presentation transcript:

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., you enter credit card information in a form and submit it pages that respond to user actions such as mouse clicks or form entries are known as event-driven pages JavaScript code can be combined with HTML elements such as buttons and text boxes to produce event-driven pages an event is a user action – e.g. mouseclick an event handler is javascript code that responds to a user’s action e.g. a button can be associated with JavaScript code that will execute when the button is clicked

3 Buttons general form of a button element:  the TYPE attribute of the INPUT element identifies the element to be a button  no ID is needed here  the VALUE attribute specifies the text label that appears on the button  the ONCLICK attribute specifies the action to take place when the button is clicked any JavaScript statement(s) can be assigned to the ONCLICK attribute

4 Buttons (cont.)  for example:  note the need for two different types of quotes  Why won’t it say anything on the button?  onClick expects JavaScript by default. No tags are needed. (What “speaks” HTML? )  Try it

5 Mouse Events  onMouseOver event handler is triggered when the user moves the mouse over a particular part of the webpage.  The programmer has to define the part of the webpage to be monitored. This can be done by using the HTML … pair of tags. Recall: what does document.bgColor='blue'; do?

6 onMouseOver <a href="#" onMouseOver= "document.bgColor='blue';"> Watch me!  The # simply refers to the current page. It doesn’t link to another page.  In this example, the background color of the page turns blue when the user moves the mouse over the link labeled "Watch me!"  Again, since two levels of quotes are needed, a second type of quote is used. How would this be interpreted if double quotes were used both times?  Please note that the page remains blue even when the mouse is moved away from the link. You do it. Watch the capitalization.

7 onMouseOut  onMouseOut event handler is triggered when the user moves the mouse away from the place on the webpage.  If the programmer doesn't want the onMouseOver change to remain when the mouse is removed, onMouseOut can be used: <a href="#" onMouseOver = "document.bgColor='blue';" onMouseOut = "document.bgColor=‘white';" > Now watch me!  Now the color of the webpage will turn white when the user moves the mouse off the link.  If it was initially white, the color will be restored. Try it. Compare the two links.

8 Dynamic Images  you can dynamically modify images  recall: causes the image stored in the file happy.gif to appear in the page  you can change the image by assigning a new value to its SRC attribute: document.getElementById(‘photo’).src = ‘sad.gif’; replaces happy.gif with sad.gif  we will also replace the alt attribute.  we will use a button

9 Dynamic Image Example See mood.html Try it. since you don’t have the pictures in your folder, you will see only the alt.

10 Text Boxes general form of a text box element:  the TYPE attribute of the INPUT element identifies the element to be a text box  the ID attribute gives the element an identity so that it can be referenced  the VALUE attribute specifies text that initially appears in the box We’ve displayed default text and allowed the user to enter text. Add a textbox

11 Output via Text Boxes now the programmer can change the text after the page is displayed:  to display output in a text box, an assignment statement is used to assign text to the value attribute as part of the assignment, we must specify the ID of the box  the general form is: document.getElementById(“TEXTBOX_ID”). value = “VALUE_TO_BE_DISPLAYED”;

Update textbox For example: document.getElementById(“name”). value = “Jane”; Add a script containing an alert and a textbox change. Now we combine button and textbox. Again note the need for 2 kinds of quotes. 12

13 <input type=“button” value=“Click Here for Lucky Number” onClick=“document.getElementById(‘number’). value = ‘15’;” /> Text Box for Displaying Output

14 Text Box Example See lucky_number_without_form.html

15 Output via Text Boxes  unlike an alert window, the text box appears as a box embedded in the page  text can be written to the box by JavaScript code (i.e., the box displays output)  A text box doesn't require the user to close the alert window after each display

16 Input and Output the same text box can be used for both input and output  user can enter a temperature in either box, then convert to other  user can enter a number, then double it by clicking the button