DOC PREVIEW
Penn CIT 597 - JavaScript and HTML

This preview shows page 1-2-23-24 out of 24 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

JavaScript and HTMLJavaScript and DOMEventsA simple event handlerCapitalizationCommon eventsExample: Simple rolloverEvents and event handlers IEvents and event handlers IIEvents and event handlers IIIEvents and event handlers IVEvents and event handlers VEvents and event handlers VIBack to the DOMThe DOM hierarchyFields of window, IFields of window, IIMethods of window, IMethods of window, IIFields of document, IFields of document, IIFields of document, IIIFields of the form objectThe EndJan 13, 2019JavaScript and HTMLSimple Event Handling2JavaScript and DOMJavaScript relies on a Document Object Model (DOM) that describes the structure of the web pageThis is not the same as the XML DOMYou can do a lot with a just a little understanding of the DOMYou use the DOM to access elements on the web pageYou can capture events without knowing the DOM at allYou need the DOM to make any changes to the web page3EventsSome (but not all) elements on the web page respond to user interactivity (keystrokes, mouse clicks) by creating eventsDifferent kinds of elements produce different eventsBrowsers are not all alike in what events are producedWe will concentrate on events from HTML form elements and commonly recognized eventsYou can put handlers on HTML form elementsIf the event isn’t generated, the handler does nothingA handler should be very shortMost handlers call a function to do their work4A simple event handler<form method="post" action=""> <input type="button" name="myButton" value="Click me" onclick="alert('You clicked the button!');"></form>The button is enclosed in a form method tells how to send the form data; action tells where to send itThe tag is input with attribute type="button"The name can be used by other JavaScript codeThe value is what appears on the buttononclick is the name of the event being handledThe value of the onclick element is the JavaScript code to executealert pops up an alert box with the given text5CapitalizationJavaScript is case sensitiveHTML is not case sensitiveonclick="alert('You clicked the button!');"The red underlined parts are HTMLThe quoted string is JavaScriptYou will frequently see onclick capitalized as onClickThe Java naming convention is easier to readThis is fine in HTML, but an error if it occurs in JavaScriptAlso note: Since we have a quoted string inside another quoted string, we need both single and double quotes6Common eventsMost HTML elements produce the following events:onClick -- the form element is clickedonDblClick -- the form element is clicked twice in close successiononMouseDown -- the mouse button is pressed while over the form elementonMouseOver -- the mouse is moved over the form element onMouseOut -- the mouse is moved away from the form elementonMouseUp -- the mouse button is released while over the form elementonMouseMove -- the mouse is movedIn JavaScript, these should be spelled in all lowercase7Example: Simple rolloverThe following code will make the text Hello red when the mouse moves over it, and blue when the mouse moves away<h1 onMouseOver="style.color='red';" onMouseOut="style.color='blue';">Hello </h1>Image rollovers are just as easy:<img src="../Images/duke.gif" width="55" height="68" onMouseOver="src='../Images/duke_wave.gif';" onMouseOut="src='../Images/duke.gif';">8Events and event handlers IThe following tables are taken from:http://developer.netscape.com/docs/manuals/js/client/ jsguide/index.htmEvent Applies to Occurs when HandlerLoadDocument body User loads the page in a browseronLoadUnloadDocument body User exits the pageonUnloadErrorImages, window Error on loading an image or a windowonErrorAbortImages User aborts the loading of an imageonAbort9Events and event handlers IIEvent Applies to Occurs when HandlerKeyDownDocuments, images, links, text areasUser depresses a keyonKeyDownKeyUpDocuments, images, links, text areasUser releases a keyonKeyUpKeyPressDocuments, images, links, text areasUser presses or holds down a keyonKeyPressChangeText fields, text areas, select listsUser changes the value of an elementonChange10Events and event handlers IIIEvent Applies to Occurs when HandlerMouseDownDocuments, buttons, linksUser depresses a mouse buttononMouseDownMouseUpDocuments, buttons, linksUser releases a mouse buttononMouseUpClickButtons, radio buttons, checkboxes, submit buttons, reset buttons, linksUser clicks a form element or linkonClick11Events and event handlers IVEvent Applies to Occurs when HandlerMouseOverLinks User moves cursor over a linkonMouseOverMouseOutAreas, links User moves cursor out of an image map or linkonMouseOutSelectText fields, text areasUser selects form element’s input fieldonSelect12Events and event handlers VEvent Applies to Occurs when HandlerMoveWindows User or script moves a windowonMoveResizeWindows User or script resizes a windowonResizeDragDropWindows User drops an object onto the browser windowonDragDrop13Events and event handlers VIEvent Applies to Occurs when HandlerFocusWindows and all form elementsUser gives element input focusonFocusBlurWindows and all form elementsUser moves focus to some other elementonBlurResetForms User clicks a Reset buttononResetSubmitForms User clicks a Submit buttononSubmit14Back to the DOMYou can attach event handlers to HTML elements with very little knowledge of the DOMHowever, to change what is displayed on the page requires knowledge of how to refer to the various elementsThe basic DOM is a W3C standard and is consistent across various browsersMore complex features are browser-dependentThe highest level element (for the current page) is window, and everything else descends from thatEvery JavaScript variable is a field of some objectIn the DOM, all variables are assumed to start with “window.”All other elements can be reached by working down from there15The DOM hierarchySource: http://sislands.com/coin70/week1/dom.htm16Fields of window, Iwindow The current window (not usually needed). self Same as window. parent If in a frame, the immediately enclosing window. top If in a frame, the outermost enclosing window. frames[ ] An array of frames (if any) within the current window. Frames are themselves windows.length The number of frames contained in this window.17Fields of window, IIdocument The HTML


View Full Document

Penn CIT 597 - JavaScript and HTML

Documents in this Course
DOM

DOM

21 pages

More DOM

More DOM

11 pages

Rails

Rails

33 pages

DOM

DOM

21 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

Rake

Rake

12 pages

Ruby

Ruby

58 pages

DOM

DOM

21 pages

Tomcat

Tomcat

16 pages

DOM

DOM

21 pages

Servlets

Servlets

29 pages

Logging

Logging

17 pages

Html

Html

27 pages

DOM

DOM

22 pages

RELAX NG

RELAX NG

30 pages

Servlets

Servlets

28 pages

XHTML

XHTML

13 pages

DOM

DOM

21 pages

DOM

DOM

21 pages

Servlets

Servlets

26 pages

More CSS

More CSS

18 pages

Servlets

Servlets

29 pages

Logging

Logging

17 pages

Load more
Download JavaScript and HTML
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view JavaScript and HTML and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view JavaScript and HTML 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?