JavaScript Part 8 George Mason University June 21, 2010.

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

Tutorial 5 Windows and Frames Section A - Working with Windows.
Chapter 1: Introduction. Contents Whats New in Dreamweaver CS4? The Dreamweaver CS4 Interface Setting Up a Site Creating a Web Page Adding Text to Your.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
The Web Warrior Guide to Web Design Technologies
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Macromedia Dreamweaver 4 Advanced Level Course. Add Rollovers Rollovers or mouseovers are possibly the most popular effects used in designing Web pages.
JavaScript, Third Edition
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
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.,
DHTML - Introduction Introduction to DHTML, the DOM, JS review.
Javascript and the Web Whys and Hows of Javascript.
Online Chapter 1 4 th Edition.  Review elements  Whitespace handling  Rule structure  Linking to an external style sheet  Alternate Style Sheets.
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 12.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
© Cheltenham Computer Training 2001 Macromedia Dreamweaver 4 - Slide No 1 Macromedia Dreamweaver 4 Advanced Level Course.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
© 2000 – All Rights Reserved - Page 1 Introduction to JavaScript Programming Part Two.
Chapter 10 Creating Pop-Up Windows, Adding Scrolling Messages, and Validating Forms HTML5 & CSS 7 th Edition.
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.
Integrating JavaScript and HTML5 HTML5 & CSS 7 th Edition.
CITS1231 Web Technologies JavaScript and Document Object Model.
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.
JavaScript, Fourth Edition
JavaScript – Part IV Event Handlers, Images, Window object William Pegram George Mason University June 3, 2010.
Using Client-Side Scripts to Enhance Web Applications 1.
Introduction to JavaScript 41 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 17.
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Tutorial 5 Windows and Frames Section B - Working with Frames and Other Objects Go to Other Objects.
Chapter 5: Windows and Frames
Chapter 7: DHTML: Object Model and Collections CIS 275—Web Application Development for Business I.
JavaScript Tutorial 1 - Introduction to JavaScript WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Introduction to JavaScript – A First.
DOM Animation Changing the DOM objects over time.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Introduction to JavaScript Objects, Properties, Methods.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript, Fourth Edition Chapter 4 Manipulating the Browser Object Model.
LEARN THE QUICK AND EASY WAY! VISUAL QUICKSTART GUIDE HTML and CSS 8th Edition Chapter 8: Working with Style Sheets.
The Web Wizard’s Guide To JavaScript Chapter 3 Working with Forms.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Working with Windows (No audio component) © Dr. David C. Gibbs
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.
HTML JAVASCRIPT. CONTENTS Javascript Example NOSCRIPT Tag Advantages Summary Exercise.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
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.
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.
PHP (cont.). 2 Functions Definition – function name(arguments){... } –syntax name as for a variable, but without $ arguments as for variables –to return.
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.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
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.
Adding Interactivity Comp 140 Fall Web 2.0 Major change in internet usage –From mostly static pages Text Graphics Simple links –To new paradigm.
Chapter 4 and 5. Objectives Introduce markup: elements and attributes How browsers interpret HTML documents Basic structure of HTML document What do style.
Tarik Booker CS 120 California State University, Los Angeles.
Module 1 Introduction to JavaScript
Using DHTML to Enhance Web Pages
Section 17.1 Section 17.2 Add an audio file using HTML
Tutorial 6 Creating Dynamic Pages
The Web Wizard’s Guide To JavaScript
Introduction to JavaScript
Presentation transcript:

JavaScript Part 8 George Mason University June 21, 2010

Topics Popup Windows Jump Menu Dynamically Changing Menus Image Rotation Moving Object on Screen Date Object

Popup Windows win=window.open("content.html","newWin", "toolbar=yes,location=yes,scrollbars=yes, resizable=yes,width=300,height=300"); -the first argument specified the content to be displayed in the window -the second argument gives the window a name, so it can be referred to through the target attribute in HTML)

Popup Windows The third argument specifies the attributes of the window; if you don't specify anything, all things are included by default, but if you specify some things, the default for the things not mentioned will be no Don't put spaces in the third argument Browsers often block popup windows Assigning the window.open to a variable, in this case win, allows you to refer to this window later in code

Select-and-Go Navigation Select a topic HTML CSS JavaScript The value attribute of the options is set equal to the page you want to jump to

Select-and-Go JavaScript function jumpPage() { newPage = document.getElementById("newLocation").op tions[document.getElementById("newLocatio n").selectedIndex].value; window.location = newPage; }

Dynamically Changing Menus <body onload="reset();" Choose sport Basketball Soccer Select Team

Dynamically Changing Menus function reset() { document.getElementById("first").selectedIndex = 0; document.getElementById("second").selectedIndex = 0; }

Dynamically Changing Menus function changesecond() { b=document.getElementById("second"); b.selectedIndex = 0; switch(document.getElementById("first").selectedIndex) { case 1: b.options.length = 3; b.options[1].text = "Lakers"; b.options[2].text = "Celtics"; break; case 2: b.options.length = 4; b.options[1].text = "US"; b.options[2].text = "England"; b.options[3].text = "Slovenia"; break; } // end switch } // end function

Dynamically Changing Jump Menus The dynamically changing second menu can also function as a jump menu (e.g. at billpegram.com) To each option, add a value that specifies the URL where one is supposed to go, e.g. b.options[1].value = " Add an onchange event handler to the second tag using window.location=document.getElementById("second").options[ selectedIndex].value;

Executing JavaScript after Specified Delay setTimeout("JS", milliseconddelay); setInterval("JS", milliseconddelay); Difference is that setTimeOut executes once, whereas setInterval executes repeatedly Earlier JS versions didn't have setInterval so one could emulate that through recursive design (function calling itself)

Animation Examples of Use of JS Delay Image Rotation Moving Object on Screen Scrolling status line – I don't like these so you'll have to do the code yourself!

Image Rotation i = 1; // initialize i, you start at the second picture since the first one is already displaying to avoid additional lag NUM_IMAGES = 2; // this and following statement are moved out of the function pics = new Array("aol.gif","microsoft.gif"); // no need for them to execute each time function rotate() { if (i>=NUM_IMAGES) i=0; // JavaScipt arrays start at 0 document.getElementById("pic").src = pics[i]; i++;}

Image Rotation (cont.) Preceding code works fine in IE8 and Opera, but in Firefox 3 the image change doesn't occur till after the time lag or one moves the cursor, whichever happen later

Moving Object on Screen x = 0; function move() { document.getElementById("pic").style.left = x; x +=1; } #pic {position:relative} This is some text This is some more text

Moving Object in Screen The preceding code works in IE8 and Opera, but not in Firefox; perhaps the caching behavior of Firefox is the culprit

Date Object d = new Date(); creates a Date object with the current day and time – i.e. when the code is executed. One can pass in values to set the Date, e.g. d = new Date("12/25/2010" ); Alternatively, one can create the date with the current date and then change it to the desired date using set methods of the Date object

Date Object setYear(year) setMonth(month) (month is 0-11) setDate(dayofmonth) getYear() getDate() getDay() (0-Sunday, 6-Saturday) getMonth() (month is 0-11)

Date Object These and other methods of the Date object can be used in conjunction with conditional statements (switch, if, if else if) to output dates in standard format