JavaScript & jQuery Session I

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Java Script Session1 INTRODUCTION.
The Web Warrior Guide to Web Design Technologies
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.
4.1 JavaScript Introduction
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Week 9 PHP Cookies and Session Introduction to JavaScript.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
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 Session 2: What is JavaScript?
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.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
ALBERT WAVERING BOBBY SENG. Week 4: JavaScript  Quiz  Announcements/questions.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 JavaScript in Context. Server-Side Programming.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 2 Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc.Slide 1.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
PHP using MySQL Database for Web Development (part II)
Module 1 Introduction to JavaScript
>> Introduction to JavaScript
Chapter 6 JavaScript: Introduction to Scripting
Tutorial 10 Programming with JavaScript
Web Development & Design Foundations with HTML5
CHAPTER 5 SERVER SIDE SCRIPTING
JavaScript is a programming language designed for Web pages.
Web Development & Design Foundations with HTML5 7th Edition
PHP Introduction.
14 A Brief Look at JavaScript and jQuery.
Chapter 19 JavaScript.
Introduction to JavaScript
JavaScript an introduction.
Objectives Insert a script element Write JavaScript comments
A second look at JavaScript
WEB PROGRAMMING JavaScript.
PHP.
JavaScript What is JavaScript? What can JavaScript do?
Web Programming Language
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
JavaScript What is JavaScript? What can JavaScript do?
HTML5 Session II Chapter 2 - How to Code, Test and Validate a Web Page Chapter 3 - How to Use HTML to Structure a Web Page
Introduction to JavaScript
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
Introducing JavaScript
PHP an introduction.
Chapter 2 - Getting Started with JavaScript
Chapter 4 - JavaScript Events, Objects, & Functions
Web Programming and Design
Web Programming and Design
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

JavaScript & jQuery www.profburnett.com Session I Chapter 2 - Getting Started with JavaScript Chapter 3 - Essential JavaScript Chapter 4 - JavaScript Events, Objects, & Functions Chapter 6 - JavaScript and the DOM Chapter 7 - JavaScript Links, Images, & Timers Chapter 5 - Testing and Debugging JavaScript www.profburnett.com Master a Skill / Learn for Life 11/9/2018 Copyright © Carl M. Burnett

Web Building Blocks Hypertext Stylization Interactivity Metadata 11/9/2018 Copyright © 2007 - 2018 Carl M. Burnett

The Web Medium Dynamic Web Site Server Side Client Side Internet Web Server Application Server Database Server HTML5 CSS JavaScript jQuery MEAN LAMP AMMP HTTP TCP/IP Java C# Python SQL XML Copyright © 2007 - 2018 Carl M. Burnett 11/9/2018

The JavaScript Event Event Occurs Script Executes HTML Element Modified Page Updated 11/9/2018 Copyright © Carl M. Burnett

How JavaScript fits into Web Architecture Client Devices Client Request to Web Server HTML Page Embedded JavaScript External JavaScript File Cloud Web Server Server Response to Client with Embedded or External JavaScript File The web architecture is based on client devices, a web server and the cloud. When a client device request a web page from a web server the server processes this request. If the request include some actionable events to happen in the web page, like a image swap or form validation, to take some of this processing demand off the server the web page designer will embed in the web page, some scripting programming code or attach a external file with the scripting programming code. This is then send to the client for processing on the client. The preferred scripting language to be used under based on the new foundation of HTML5, is JavaScript. All browsers today include a JavaScript interpreter that runs the JavaScript language to interpret the code. 11/9/2018 Copyright © Carl M. Burnett

JavaScript for Current Date and Year var today = new Date(); document.write("Current date: "); document.write(today.toDateString()); </script> </p> document.write("© "); document.write(today.getFullYear()); document.write(", San Joaquin Valley Town Hall") Example 11/9/2018 Copyright © Carl M. Burnett

Object Oriented Programming Concepts Class Objects Inheritance Data Encapsulation Metadata Polymorphism 11/9/2018 Copyright © Carl M. Burnett

Class Characteristics Class = Containers Class = Structure Glass Plastic Metal Class is Instantiated State Structure Behaviors Hierarchy Access Class = Behaviors Pour Fill Shake Class = Hierarchy Class = Access 1. Private 2. Protected 3. Public 11/9/2018 Copyright © Carl M. Burnett

Objects Data Structures Properties Methods 11/9/2018 Copyright © Carl M. Burnett

Inheritance Object or Class is based on another Object Multiple Inheritance Multilevel Inheritance  Single Inheritance Hybrid Inheritance Hierarchical Inheritance  11/9/2018 Copyright © Carl M. Burnett

Data Encapsulation Metadata – Data about Data Record House No. Street Street Type City State Address 123 Post Avenue Westbury New York Record Salutation First Name MI Last Name Suffix Person Ms. Sally M Smith III Record 11/9/2018 Copyright © Carl M. Burnett

Polymorphism Polymorphism lets methods react to system behaviors at runtime. Where Can I buy you? At the Target Store around the corner. How Much Do You Cost? $12 11/9/2018 Copyright © Carl M. Burnett

The Document Object Model (DOM) for a Web Page Objects Properties Methods Inheritance Data Encapsulation HTML <html> </html> Head <head> </head> Body <body> </body> Title <title> </title> section <section> </section> h1 <h1> </h1> ul <ul> </ul> p <p> </p> Text li <li> </li> What is important to understand is the Document Object Model. But first let review what makes up an object. In Chapter 1 we covered what a object is and what characteristics a object possess. 1. Object posses properties. These can be such things as size, color, and shape. 2. Object posses methods. These can be move, pour, open and close. 3. Objects can inherit properties, method and data from a parent object. 4. And objects can encapsulated data by using metadata. With this understanding about the characteristics about an object we can apply this same understanding to the objects that make up a web page. In this case, the overarching parent object of a web page is the HTML declaration. This object is created with the html opening and closing tags. The tags create the HTML object and all object oriented characteristics of the HTML object can be changed based on triggering events. In order for these characteristics to be changed on the client side, a scripting language must be used. In the case, the standard is JavaScript and this language is interpreted through the JavaScript interpreter engine that is part of all browsers. The next object in the web page document object model is the head. This object is created by the head opening and closing tags. It can inherit any characteristics from its parent object, the HTML object. The next object is the body. This object is created by the body opening and closing tags. It can inherit any characteristics from its parent object, the HTML object. A child object of the Head object is the Title object. This object is created by the title opening and closing tags. It can inherit any characteristics from its parent object, the Head object. The next object is the new HTML5 document object called a section. This object is created by the section opening and closing tags. It can inherit any characteristics from its parent object, the body object. The next objects can be many objects to define the content of body or section or any other object container. These objects inlcude the h1 object, the ul object and the p object. These objects are created by the h1, ul, and p opening and closing tags. That can inherit any characteristics from its parent object, the body object. The last objects are the li objects that are created with the li tags. They can inherit any characteristics from its parent object, the ul object. Each of these object can contain data and for the h1 object, the ul li objects and p object all contain textual data that can be changed with the JavaScript language. 11/9/2018 Copyright © Carl M. Burnett

The JavaScript DOM Event Cycle Page Loaded Event Occurs Script Executes DOM Modified Page Updated 11/9/2018 Copyright © Carl M. Burnett

How to Include JavaScript in a HTML Document A script element in the head section that loads an external JavaScript file <script src="image_swap.js"></script> A script element that embeds JavaScript in the head section <head> ... <script> function printTOC() { window.print(); } </script> </head> Example 11/9/2018 Copyright © Carl M. Burnett

How to Include JavaScript in a HTML Document A script element that embeds JavaScript in the body <p>© <script> var today = new Date(); document.writeln(today.getFullYear()); </script> </p> How to use the noscript tag <script> var today = new Date(); document.writeln(today.getFullYear()); </script> <noscript>2011</no 11/9/2018 Copyright © Carl M. Burnett

How to Include JavaScript in a HTML Document Two attributes of the script element Attributes Description src Location and Name of External JavaScript File. type HTML5 (Omit) - otherwise - “text/javascript” 11/9/2018 Copyright © Carl M. Burnett

JavaScript Syntax Rules JavaScript is case-sensitive. Each JavaScript statement ends with a semicolon. JavaScript ignores extra whitespace within statements. 11/9/2018 Copyright © Carl M. Burnett

Camel Casing Notation taxRate tax_rate calculateClick calculate_click emailAddress email_address futureValue future_value 11/9/2018 Copyright © Carl M. Burnett

JavaScript Reserved Words 11/9/2018 Copyright © Carl M. Burnett

JavaScript Code Comments /* this application validates a user's entries for joining our email list */ var $ = function(id) { // the $ function return document.getElementById(id); } // this function gets and validates the user entries var joinList = function() { var emailAddress1 = $("email_address1").value; var emailAddress2 = $("email_address2").value; var firstName = $("first_name").value; var isValid = true; // validate the first entry if (emailAddress1 == "") { $("email_address1_error").firstChild.nodeValue = "This field is required."; isValid = false; // set valid switch to off } else { $("email_address1_error").firstChild.nodeValue = ""; // validate the second entry ... }; Block comments begin with /* and end with */. Single-line comments begin with two forward slashes and continue to the end of the line. Guidelines for using comments Use comments to describe portions of code that are hard to understand. Use comments to disable portions of code that you don’t want to test. Don’t use comments unnecessarily. 11/9/2018 Copyright © Carl M. Burnett

JavaScript on W3Schools - I Where To Output Statements Syntax Comments Style Guide Best Practices Reserved Words Common Mistakes 11/9/2018 Copyright © Carl M. Burnett

Exercise I Setup Development Environment 11/9/2018 Copyright © Carl M. Burnett

JavaScript on W3Schools - I Type Conversion Bitwise Regular Expressions Errors Strict Mode Hoisting HTML DOM Browser DOM JavaScript Reference 11/9/2018 Copyright © Carl M. Burnett

Variable Declaration and Assignment Syntax var variableName; variableName = value; Examples var counter; // declaration statement; // value is undefined counter = 1; // assignment statement; // value is 1 var sum, average; // declares two variables   sum = 0, average = 0; // assigns values to two // variables 11/9/2018 Copyright © Carl M. Burnett

JavaScript’s Arithmetic Operators Name Description + Addition Adds two operands. - Subtraction Subtracts the right operand from the left operand. * Multiplication Multiplies two operands. / Division Divides the right operand into the left operand. The result is always a floating-point number. % Modulus Divides the right operand into the left operand and returns the remainder. Increment Adds 1 to the operand. -- Decrement Subtracts 1 from the operand. 11/9/2018 Copyright © Carl M. Burnett

JavaScript on W3Schools - II Variables Operators Arithmetic Assignment Data Types 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise II - Variables Complete Variable Exercises Exercise 2 Exercise 3 Exercise 4 Exercise 5 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise II - Arithmetic Complete Arithmetic Exercises Exercise 2 Exercise 3 Exercise 4 Exercise 5 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise II - Assignment Complete Assignment Exercises Exercise 2 Exercise 3 Exercise 4 Exercise 5 11/9/2018 Copyright © Carl M. Burnett

Concatenation Operators Description + Concatenates two values. += Adds the result of the expression to the end of the variable. 11/9/2018 Copyright © Carl M. Burnett

JavaScript on W3Schools - III Scope Events Strings String Methods Numbers Number Methods Math Random 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise III - Events Complete Event Exercises Exercise 2 Exercise 3 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise III - Strings Complete String Exercises Exercise 2 Exercise 3 Exercise 4 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise III - String Methods Complete String Method Exercises Exercise 2 Exercise 3 Exercise 4 Exercise 5 Exercise 6 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise III – Numbers Complete Number Exercises Exercise 2 Exercise 3 Exercise 4 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise III - Math Complete Math Exercises Exercise 2 Exercise 3 Exercise 4 11/9/2018 Copyright © Carl M. Burnett

Common Methods for Window Object alert(string) prompt(string, default) print() The syntax for calling a method of an object objectName.methodName(parameters) A statement that calls the alert() method of the window object window.alert("This is a test of the alert method"); 11/9/2018 Copyright © Carl M. Burnett

Two Methods of Window Object parseInt(string) parseFloat(string) The parsing that’s done by the parse methods Only the first number in the string is returned. Leading and trailing spaces are removed. If the first character cannot be converted to a number, NaN is returned. 11/9/2018 Copyright © Carl M. Burnett

Two Methods of Document Object write(string) writeln(string) 11/9/2018 Copyright © Carl M. Burnett

JavaScript on W3Schools - IV Object Definitions Object Properties Object Methods Object Constrictors Object Prototypes Function Definitions Function Parameters Function Invocation Function Call Function Apply Function Closures 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise IV - Functions Complete Function Exercises Exercise 2 Exercise 3 Exercise 4 Exercise 5 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise IV - Objects Complete Object Exercises Exercise 2 Exercise 3 11/9/2018 Copyright © Carl M. Burnett

JavaScript on W3Schools - V Dates Date Formats Date Methods Arrays Array Methods Array Sort 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise V - Dates Complete Date Exercises Exercise 2 Exercise 3 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise V - Arrays Complete Array Exercises Exercise 2 Exercise 3 Exercise 4 Exercise 5 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise V - Array Methods Complete Array Methods Exercises Exercise 2 Exercise 3 Exercise 4 11/9/2018 Copyright © Carl M. Burnett

Greater than or equal to Relational Operators Operator Name == Equal to != Not equal to < Greater than > Less than >= Greater than or equal to <= Less than or equal to 11/9/2018 Copyright © Carl M. Burnett

Increment a Counter Variable by 1 var counter = 1; // counter = 1 counter = counter + 1; // counter now = 2 counter += 1; // counter now = 3 counter++; // counter now = 4 11/9/2018 Copyright © Carl M. Burnett

JavaScript on W3Schools - VI Booleans Comparisons Conditionals Switch Loop For Loop While Break 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise VI - Comparisons Complete Comparison Exercises Exercise 2 Exercise 3 Exercise 4 Exercise 5 Exercise 6 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise VI - Conditionals Complete Conditional Exercises Exercise 2 Exercise 3 Exercise 4 Exercise 5 Exercise 6 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise VI - Switch Complete Switch Exercises Exercise 2 Exercise 3 Exercise 4 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise VI - Loops Complete Loop Exercises Exercise 2 Exercise 3 Exercise 4 Exercise 5 Exercise 6 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise VI - Loop While Complete Loop While Exercises Exercise 2 Exercise 3 Exercise 4 Exercise 5 11/9/2018 Copyright © Carl M. Burnett

JavaScript Exercise VI - Break Complete Break Exercises Exercise 2 Exercise 3 Exercise 4 Exercise 5 11/9/2018 Copyright © Carl M. Burnett

Debugging Debugging 11/9/2018 Copyright © Carl M. Burnett

Methods to Debug a Webpage W3C Developer Tools Firefox Developer Tools Chrome Dev Tools IE Developer Tools MS Edge Developer Tools 11/9/2018 Copyright © Carl M. Burnett