JavaScript Describe common uses of JavaScript in Web pages.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
The Web Warrior Guide to Web Design Technologies
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION 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.
Javascript and the Web Whys and Hows of Javascript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
Server vs Client-side validation. JavaScript JavaScript is an object-based language. JavaScript is based on manipulating objects by modifying an object’s.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
JavaScript Part 1.
JavaScript 1. What is JavaScript? JavaScript allows web authors to create dynamic pages that react to user interaction. It is an Object-based because.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
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.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Tutorial 10 Programming with JavaScript
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
Using Client-Side Scripts to Enhance Web Applications 1.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
JavaScript - A Web Script Language Fred Durao
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
Intro to JavaScript. Some simple examples Examples from our webpage Examples from Andrews webpage Today’s Example.
1 JavaScript
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
1 JavaScript in Context. Server-Side Programming.
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.
Making dynamic pages with javascript Lecture 1. Java script java versus javascript Javascript is a scripting language that will allow you to add real.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Pertemuan 5 IT133 Pengembangan Web JavaScript. What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
Copyright © Terry Felke-Morris Web Development & Design Foundations with HTML5 8 th Edition CHAPTER 14 KEY CONCEPTS 1 Copyright.
Web Development & Design Foundations with HTML5
Parts of Chapter 14 Key Concepts
Web Development & Design Foundations with HTML5 7th Edition
Introduction to Scripting
Web Development & Design Foundations with HTML5 7th Edition
14 A Brief Look at JavaScript and jQuery.
WEB PROGRAMMING JavaScript.
Introduction to JavaScript
Web Development & Design Foundations with H T M L 5
CS105 Introduction to Computer Concepts
Web Development & Design Foundations with H T M L 5
Tutorial 10: Programming with javascript
JavaScript: Introduction to Scripting
Web Programming and Design
CS105 Introduction to Computer Concepts JavaScript
Web Development & Design Foundations with HTML5 7th Edition
Presentation transcript:

JavaScript Describe common uses of JavaScript in Web pages. Describe the purpose of the Document Object Model and list some common events. Create a simple JavaScript using the <script> tag and the alert() method. Describe the considerations for XHTML conformance and JavaScript. Use variables, operators and the if control structure. Create a basic form validation script.

What is JavaScript? Object-oriented scripting language. Used to work with the objects associated with a web page document --the window, the document, the elements such as forms, images, links, etc Originally developed by Netscape and called LiveScript Netscape collaborated with Sun Microsystems on modifications to the language and it was renamed JavaScript JavaScript is NOT Java

Common Uses of JavaScript Display a message box Select list navigation Edit and validate form information Create a new window with a specified size and screen position Image Rollovers Status Messages Display Current Date Calculations

Coding JavaScript JavaScript code can be added to a web page using two different techniques: Place Javascript code between <script> tags Place Javascript code as part of an event attached to an XHTML element

JavaScript Using <script> tags The script tag A container tag May be placed in either the header or the body section of a web page <script language="JavaScript" type=”text/javascript”> <!- - alert("Welcome to Our Site"); // - -> </script>

Questions Describe two uses of JavaScript. Describe two XHTML tag used to add JavaScript to a Web page. True or False. JavaScript is the same as Java.

Document Object Model (DOM) The DOM defines every object and element on a web page. Its hierarchical structure can be used to access page elements and apply styles to page elements. A portion of the DOM is shown at the right.

Object An object is a thing or entity. Browser window Submit button Web page document

Property A property is a characteristic or attribute of an object. The background color of a web page document document.bgcolor The date the web page file was last modified document.lastmodified The src file of an image object image1.src

Method A method is an action (a verb) Writing text to a web page document document.write() Submitting a form form1.submit()

JavaScript and Events Events are actions that the visitor to the web page can take such as clicking (onclick), placing the mouse on an element (onmouseover), removing the mouse from an element (onmouseout), loading the page (onload), unloading the page (onunload), etc. JavaScript can be configured to perform actions when these and other events occur. The JavaScript code is added directly to the XHTML tag with the type of event as an attribute. The value of the event attribute will contain one or more JavaScript statements.

Events Event Event Handler click onclick load onload mouseover onmouseover mouseout onmouseout submit onsubmit unload onunload

JavaScript Coding for Events The sample code below will display an alert box when the mouse is placed over a link. <a href=”home.htm” onmouseover=”alert(‘Click to go home’)”>Home</a>

JavaScript Debugging(1) Check the syntax of the statements that you typed - pay very close attention to upper and lower case letters, spaces, and quotations. Verify that you have saved the page with your most recent changes. Verify that you are testing the most recent version of the page (refresh or reload the page) If you get an error message, Use the error messages that are displayed by the browser.

JavaScript Debugging(2) Use the Firefox or Mozilla browser: Type “javascript: in the address bar to view the JavaScript console. The JavaScript Console will indicate an issue and the line number This may not be exactly where the problem is Sometimes the error is a one or two lines above the indicated line number.

Questions With respect to objects, describe the difference between a property and a method. Feel free to use words like “thing,” “action,” “description,” “attribute,” and so forth. What is the difference between an event and an event handler? Where are event handlers placed in the XHTML document?

Variable var userName; userName = "Karen"; document.write(userName); A variable is a placeholder for information. The variable is stored in the computer’s memory (RAM). var userName; userName = "Karen"; document.write(userName);

Prompts prompt() method Displays a message and accepts a value from the user myName = prompt(“prompt message”); The value typed by the user is stored in the variable myName

Arithmetic Operators Operator Description Example Value of Quantity = assign quantity = 10 10 + addition quantity = 10 + 6 16 - subtraction quantity = 10 - 6 4 * multiplication quantity = 10 * 2 20 / division quantity = 10 / 2 5

Comparison Operators Operator Description Example Sample values of quantity that would result in true = = Double equals sign (equivalent) “is exactly equal to” quantity = = 10 10 > Greater than quantity > 10 11, 12 (but not 10) > = Greater than or equal to quantity > = 10 10, 11, 12 < Less than quantity < 10 8, 9 (but not 10) < = Less than or equal to quantity < = 10 8, 9, 10 ! = Not equal to quantity ! = 10 8, 9, 11 (but not 10)

Decision Making if (condition) { … commands to execute if condition is true } else { … commands to execute if condition is false

Function A function is a block of one or more JavaScript statements with a specific purpose, which can be run when needed. function function_name() { ... JavaScript statements … }

Defining the Function Calling the Function function showAlert() { alert("Please click OK to continue."); } Calling the Function showAlert();

Questions What is a function definition? Why do you call a function? Can you call a function more than once?

Form Validation It is common to use JavaScript to validate form information before submitting it to the Web server. Is the name entered? Is the e-mail address of correct format? Is the phone number in the correct format? See Hands-on Practice 14.8

Validating Form Fields Use the “” or null to check to determine if a form field has information if (document.forms[0].userName.value == "" ) { alert("Name field cannot be empty."); return false; } // end if

JavaScript & Accessibility Don’t expect JavaScript to always function for every visitor Some may have JavaScript disabled Some may be physically unable to click a mouse Provide a way for your site to be used if JavaScript is not functioning Plain text links E-mail contact info

JavaScript Resources Beginning JavaScript Tutorials http://www.pageresource.com/jscript/index.html JavaScript Tutorial for the Total Non-Programmer http://www.webteacher.com/javascript/ More Beginning JavaScript Tutorials http://echoecho.com/javascript.htm Core JavaScript 1.5 Reference Manual http://www.webreference.com/javascript/reference/core_ref The JavaScript Source http://javascript.internet.com

Questions What is meant by the term “form data validation”? Give three examples of form data that may require validation. Should you always expect your JavaScript to “work” – why or why not?