JavaScript Events with XHTML Please use speaker notes for additional information!

Slides:



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

The Web Warrior Guide to Web Design Technologies
20-Jun-15 JavaScript and HTML Simple Event Handling.
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.
JavaScript Lesson 1 TBE 540. Prerequisites  Before beginning this lesson, the learner must be able to… Create a basic web page using a text editor and/or.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
Using color and fonts in HTML and XHTML Please use speaker notes for additional information!
Introduction to JavaScript Events As usual, please use the speaker notes for additional information!
Inline, Internal, and External FIle
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Web Programming Material From Greenlaw/Hepp, In-line/On-line: Fundamentals of the Internet and the World Wide Web 1 Introduction The JavaScript Programming.
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.,
Javascript and the Web Whys and Hows of Javascript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
Image Use. Agenda Ordinary display of image: height, width, alt Rollovers Images as links (remove blue surround) Background images: stretch, tile, xonly/yonly.
Links in HTML. Hyperlinks or links Millions of linked web pages make up the World Wide Web Used to connect a web page to another web page on the same.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
Using images with XHTML Please use speaker notes for additional information!
JavaScript Part 1.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
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.
Getting Started with HTML Please use speaker notes for additional information!
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
Client Side Programming with JavaScript Why use client side programming? Web sides built on CGI programs can rapidly become overly complicated to maintain,
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 14 - Dynamic HTML: Event Model Outline 14.1 Introduction 14.2 Event onclick 14.3 Event onload.
Lesson 4.
 HTML is hypertext markup language. It is a way for people to display their information with more complex pictures and text displays. Before HTML, messages.
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
JavaScript Adding active content to websites. Goals Understand structure of JavaScript Understand rules of coding Add active content to WebPages Add functions.
Tables with XHTML Please use speaker notes for additional information!
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
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.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
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.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
CSS with XHTML Please use speaker notes for additional information!
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.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript JavaScript is a programming language that web browsers understand. You can use it to make your web pages interactive by: Responding to user.
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
Functions Wouldn’t it be nice to be able to bring up a new animal and paragraph without having to reload the page each time? We can! We can place the.
Tarik Booker CS 120 California State University, Los Angeles.
Third lecture Event 27/2/2016 JavaScript Tutorial.
Introduction to.
JavaScript and HTML Simple Event Handling 11-May-18.
JavaScript is a programming language designed for Web pages.
JavaScript and HTML Simple Event Handling 19-Sep-18.
Introduction to DOM.
USING IMAGES This is the bottom of the page. Note the alignment of having text before and after, at the top, in the middle and at the bottom. Code is on.
JavaScript Basics What is JavaScript?
JavaScript is a scripting language designed for Web pages by Netscape.
Introduction to Programming and JavaScript
Web Programming and Design
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

JavaScript Events with XHTML Please use speaker notes for additional information!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " JavaScript Rollover.alignright { text-align: right; }.fontverylarge { font-size: 36pt; } Mouse over here! The first thing to note is the use of a href=“#”. This means that the same page should be loaded if you click on the words Mouse over here! The class establishes the size of the words Mouse over here! as 36 pt. The event onmouseover means that if a mouse is rolled over the words Mouse over here! The alert box will be displayed with the message Testing mouse over! This code means that I do not have to tell the encoding when I validate. You should start to use these 4 lines in your code.

Some of the first interesting things you can do with JavaScript are event-driven. Event driven means that a particular action causes something to happen. JavaScript has clicks that can detect events such as onclick, onmouseover, onmouseout. This page illustrates the mouse over and mouse out events. <a href="#" onmouseover="document.CISimage.src='CISa.gif';" onmouseout="document.CISimage.src='CISb.gif';"> Notice that the # means this page to HTML and so setting the HREF to the # means stay on the same page. You can also use the name of the current page. In this example, there is a onmouseover and a onmouseout event. If the onmouseover event happens then the CISa.gif image is loaded. If the onmouseout event happens then the image CISb.gif is loaded. Note that img src established what image should be there when the page is loaded. Name names the area, it does not validate strict which is why I validated transitional. When I changed to id, which is more acceptable, this did not run on some reasonably recent browsers. So instead of making the change, I chose to validate transitional. Now let’s look at the command: document.CISimage.src=‘CISa.gif’; Read this as CISa.gif is the source of the area named CISimage on the document. The document is the part of the window that holds your page.

Now looking at the construction of the command. Note that onmouseover should be written exactly that way because of case sensitivity issues related to XHTML. In regular HTML, it was written as onMouseOver. In the first example, I am saying the mouse rolls over the words Mouse over here!, then the alert box will come up with the message that says Testing mouse over. Notice the use of the double quote, single quotes, parenthesis and semi-colon. Inside the double quotes is the JavaScript command which should end with a semi-colon. What we are doing is putting the JavaScript inside the quotes of an event. The event is onmouseover. The alert needs a message and the message inside parenthesis and enclosed in single quotes. If you have quotes within quotes the inner quotes must be single to differentiate. The alert() function puts the message in the () inside the message box. Note that all functions in JavaScript have the form functionName() where sometimes the parenthesis contain data and sometimes they are empty. We will see more of this in later examples. Note one last thing that has nothing to do with JavaScript, because I wanted to Mouse over here! to be large and aligned to the right, I used the paragraph to align to the right and the font to change the font. These are not needed for the JavaScript. On the next example, I am using both onmouseover and onmouseout. I went into PhotoEditor and did a invert with the CISa.gif image and saved it as CISb.gif. Then I can have one image show when the mouse rolls over the image and a second image show when the mouse rolls out. When I work with an image, I need to be aware of the fact that frequently browers will not let the developer put events inside image tags. So what you have to do is set up the HREF equal to # and put the events inside that and then set up the image source with name as shown above. When the image is firstloaded it will show the image in IMG SRC which in this case is CISa.gif. When the mouse goes over that same image is shown. When the mouse goes out a different image is shown (in this case the inverted image). The dots in document.CISimage.src have special meaning to JavaScript. It will go to the last dot and work backward in the interpretation. So this essentially reads as change the src of CISimage which is in the document. This follows a document object model hierarchy (DOM) which can be referenced in many tutorials on JavaScript. To make things more efficient you can preload the images. I will illustrate a preload in another example. One other thing to note - because single and double quotes have special meanings, you cannot use them in the ordinary way in your text. If you want to use the quotes in your text you do it with Jane\'s where the \ tells JavaScript to use the single quote instead of interpreting it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " JavaScript Rollover - another example.borderno { border: none; } var CISa_image = new image(); CISa_image.src = "CISa.gif"; var CISb_image = new image(); CISb_image.src = "CISb.gif"; The code above preloads two images. <a href="#" onmouseover="CISimage.src='CISa.gif';" onmouseout="CISimage.src='CISb.gif';"> Here I am using JavaScript in the head to preload the images. This means that the images would load faster if this was an extensive page. The borderno class is set up to have no borders, so when I use it, I do not see the blue lines around the image. I did not use document here, document is assumed.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " Java rotate body { background: beige; } div { text-align: center; } var originalz = new image(); originalz.src = "house.jpg"; var flipz = new image(); flipz.src = "houseusd.jpg"; Here is an image to roll the mouse over Rolling the mouse over and out are called events. <a href="javamousex.html" onmouseover="document.snowhouse.src='house.jpg';" onmouseout="document.snowhouse.src='houseusd.jpg';"> <img src="houseusd.jpg" name="snowhouse" width="577" height="384" alt="house" />

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " Button Click This uses a button that the user can click on to raise an alert. This shows the onclick event associated with a form button.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " Events in Java p { text-align: center; } Events are a different type of code because they are built directly into the HTML code. They aren't scripts because their design was to be embedded in the HTML. First I am going to illustrate mouse over/out events. <a href="tryevent1x.html" onmouseover="alert('Testing events...')">ALERT MOUSE TEST!

<a href="tryevent1x.html" onmouseover="document.bgColor='beige'">CHANGE BACKGROUND TO BEIGE! <a href="tryevent1x.html" onmouseover="document.bgColor='aqua'">CHANGE BACKGROUND TO AQUA!

<a href="tryevent1x.html" onmouseover="document.bgColor='pink'" onmouseout="document.bgColor='green'">CHANGE BACKGROUND!

<a href="tryevent1x.html" onmouseover="window.status='Testing roll over'; return true" onmouseout="window.status='Testing roll out'; return true">WINDOW STATUS TRUE TEST!

<a href="tryevent1x.html" onmouseover="window.status='Testing roll over'" onmouseout="window.status='Testing roll out'">WINDOW STATUS TEST!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " Events in Java p { text-align: center; } Events are a different type of code because they are built directly into the HTML code. They aren't scripts because their design was to be embedded in the HTML. First I am going to illustrate mouse over/out events. <a href="tryevent1x.html" onmouseover="alert('Testing events...')">ALERT MOUSE TEST! <a href="tryevent1x.html" onmouseover="document.bgColor='beige'">CHANGE BACKGROUND TO BEIGE! <a href="tryevent1x.html" onmouseover="document.bgColor='aqua'">CHANGE BACKGROUND TO AQUA! <a href="tryevent1x.html" onmouseover="document.bgColor='pink'" onmouseout="document.bgColor='green'">CHANGE BACKGROUND! <a href="tryevent1x.html" onmouseover="window.status='Testing roll over'; return true" onmouseout="window.status='Testing roll out'; return true">WINDOW STATUS TRUE TEST! <a href="tryevent1x.html" onmouseover="window.status='Testing roll over'" onmouseout="window.status='Testing roll out'">WINDOW STATUS TEST! Note: The return true clause allows the default in the window status to be over ridden.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " Events in Java body { background: pink; } p { text-align: center; } This example illustrates the on click event. <a href="tryevent2.html" onclick="alert('Testing events...')">ALERT ON CLICK TEST! Using onFocus, when you click on the box in the form, the window will display the activity to be done. Using onchange tells when the data has been changed. Course information: <input type="text" size="5" id="crscode" onfocus="window.status='Enter course code'" /> <input type="text" size="25" name="crsname" onfocus="window.status='Enter course name'" onchange="alert('The data has been changed')" /> MAJOR:

Computer Information Systems Business Administration Other major The onBlur means that you have lost focus on an answer. <input type="text" size="25" name="crsinst" onfocus="window.status='Enter instructor name'" onblur="alert('Did you enter instructor name?')" /> Comments:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " More events var mycolor; var myfont; This shows some uses of the onclick event <a href = "#" onclick="window.document.bgColor='beige'">Make background beige <a href = "#" onclick="window.document.fgColor='blue'" >Make font blue <a href="#" onclick="mycolor=prompt('Enter your choice of background color',''); window.document.bgColor=mycolor;">Change the background color <a href="#" onclick="myfont=prompt('Enter your choice of font color',''); window.document.fgColor=myfont;">Change the font color <a href="#" onclick="document.originalz.src='CISb.gif';">Click here to change the top image! <a href="#" onclick="document.originalz.src='CISa.gif'; return false;">Click here to change the top image back!

Note: Return false is another way to tell the browser not to follow the link given. The Prompt puts up a box where the user can enter input. Note that in the prompt I have some words that will become the title, then I entered a comma and two quotes together. The two quotes together make the box where I want the user to enter information blank. If I wanted to put a default in the user entry line I could put in between the quotes. <a href="#" onclick="mycolor=prompt('Enter your choice of background color','pink'); window.document.bgColor=mycolor;">Change the background color Note also that there are two things that I want to do on the click event, one is to get the user to pick a color or in this case, go with the default. The other is to use that color to change the background. The double quotes are around both of these.