Java Script: Objects (Chapter 12 in [2]). 2 Outline Introduction Introduction Thinking About Objects Thinking About Objects Math Object Math Object String.

Slides:



Advertisements
Similar presentations
Intro to Javascript CS Client Side Scripting CS380 2.
Advertisements

Introducing JavaScript
JavaScript and AJAX Jonathan Foss University of Warwick
 2008 Pearson Education, Inc. All rights reserved JavaScript: Objects.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Session 8 JavaScript/Jscript: Objects Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
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.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
6.1 JavaScript Objects and Object- Oriented Programming (OOP)
1 JavaScript/Jscript 6 Objects. 2 Introduction Up till now –JavaScript used to illustrate basic programming concepts JavaScript can also –Manipulate every.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 12 - JavaScript: Objects Outline 12.1 Introduction 12.2 Thinking About Objects 12.3 Math Object.
Introduction to scripting
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 16: Working with Text.
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
JavaScript, Fourth Edition
1 JavaScript: Objects and Object Models October 25, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel,
 2002 Prentice Hall, Inc. All rights reserved.2 Chapter 2 — Introduction to HyperText Markup Language 4: Part I Outline 2.1Introduction 2.2Markup Languages.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
JavaScript: Objects Outline 12.1 Introduction 12.2 Thinking About Objects 12.3 Math Object 12.4 String Object Fundamentals of Characters and Strings.
Chapter 8 Cookies And Security JavaScript, Third Edition.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Objects.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Screen Scraping Application Introducing String Processing.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 13 – JavaScript/Jscript: Objects Outline 13.1Introduction 13.2Thinking About Objects 13.3.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e. 2.
 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.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2001 Deitel & Associates, Inc. All rights reserved. 1 Chapter 18 – JavaScript/Jscript: Objects Outline 18.1Introduction 18.2Thinking About Objects 18.3.
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
COP 3813 Intro to Internet Computing Prof. Roy Levow Lecture 4 JavaScript.
Chapter 12: Objects CIS 275—Web Application Development for Business I.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing a Line of Text in a Web Page 7.3 Another JavaScript.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
(Some from Chapter 11.9 – “Web” 4 th edition and
IS2802 Introduction to Multimedia Applications for Business Lecture 8: JavaScript and Cookies Rob Gleasure
INTRODUCTION JavaScript can make websites more interactive, interesting, and user-friendly.
JavaScript: Objects 1 © by Pearson Education, Inc. All Rights Reserved.
JavaScript: Objects 1 © by Pearson Education, Inc. All Rights Reserved.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 12 - JavaScript: Objects Outline 12.1 Introduction 12.2 Thinking About Objects 12.3 Math Object.
REEM ALMOTIRI Information Technology Department Majmaah University.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 15 JavaScript.
11 JavaScript: Objects.
Chapter 6 JavaScript: Introduction to Scripting
JavaScript Objects.
Introduction to Scripting
Chapter 12 - JavaScript: Objects
WEB PROGRAMMING JavaScript.
INFO/CSE 100, Spring 2005 Fluency in Information Technology
Chapter 12 - JavaScript: Objects
Tutorial 10 Programming with JavaScript
Chapter 7 - JavaScript: Introduction to Scripting
JavaScript: Objects.
Chapter 12 - JavaScript: Objects
JavaScript: Introduction to Scripting
11 JavaScript: Objects.
Presentation transcript:

Java Script: Objects (Chapter 12 in [2])

2 Outline Introduction Introduction Thinking About Objects Thinking About Objects Math Object Math Object String Object String Object Date Object Date Object Boolean and Number Objects Boolean and Number Objects document Object document Object window Object window Object Using Cookies Using Cookies Final JavaScript Example Final JavaScript Example Web Resources Web Resources

3 Introduction Use JavaScript to manipulate every element of XHTML document from a script Use JavaScript to manipulate every element of XHTML document from a script Reference for several of JavaScript ’ s built-in objects Reference for several of JavaScript ’ s built-in objects Demonstrates the capabilities Demonstrates the capabilities

4 Thinking About Objects Objects Objects Attributes Attributes Behaviors Behaviors Encapsulate data and methods Encapsulate data and methods Property of information hiding Property of information hiding Details hidden within the objects themselves Details hidden within the objects themselves

5 Math Object Allow the programmer to perform many common mathematical calculations Allow the programmer to perform many common mathematical calculations

6 Math Object Fig. 12.1Math object methods.

7 Math Object

8

9 String Object JavaScript ’ s string and character-processing capabilities JavaScript ’ s string and character-processing capabilities Appropriate for processing names, addresses, credit card information, etc. Appropriate for processing names, addresses, credit card information, etc.

10 Fundamentals of Characters and Strings Characters Characters Fundamental building blocks of JavaScript programs Fundamental building blocks of JavaScript programs String String Series of characters treated as a single unit Series of characters treated as a single unit

11 Methods of the String Object Fig String object methods.

12 Methods of the String Object Fig String object methods.

13 Methods of the String Object

14 Character Processing Methods charAt charAt Returns the character at specific position Returns the character at specific position charCodeAt charCodeAt Returns Unicode value of the character at specific position Returns Unicode value of the character at specific position fromCharCode fromCharCode Returns string created from series of Unicode values Returns string created from series of Unicode values toLowerCase toLowerCase Returns lowercase version of string Returns lowercase version of string toUpperCase toUpperCase Returns uppercase version of string Returns uppercase version of string

17 Searching Methods indexOf and lastIndexOf indexOf and lastIndexOf Search for a specified substring in a string Search for a specified substring in a string

21

22 In-Class Exercise #1 Modify the program shown in pp to output the number of occurrences of substrings within the original string. Modify the program shown in pp to output the number of occurrences of substrings within the original string.

23 Splitting Strings and Obtaining Substrings Tokenization Tokenization The process of breaking a string into tokens The process of breaking a string into tokens Tokens Tokens Individual words Individual words Separated by delimiters Separated by delimiters

26

27 XHTML Markup Methods Anchor Anchor Blink Blink blinking text blinking text Fixed Fixed monospaced text monospaced text Strike Strike strike out text strike out text Subscript Subscript subscript subscript Superscript Superscript superscript superscript

30 Date Object Provides methods for date and time manipulations Provides methods for date and time manipulations

31 Date Object

32 Date Object

33 Date Object

37 Question Browse the HTML file given in the last three pages. Do you see the same results? Browse the HTML file given in the last three pages. Do you see the same results?

38 Boolean and Number Objects Object wrappers for boolean true / false values and numbers Object wrappers for boolean true / false values and numbers

39 Boolean and Number Objects

40 Boolean and Number Objects

41 document Object Manipulate document that is currently visible in the browser window Manipulate document that is currently visible in the browser window

42 document Object

43 window Object Provides methods for manipulating browser window Provides methods for manipulating browser window

window.html 1 of 7

window.html 2 of 7

window.html 3 of 7

window.html 4 of 7

window.html 5 of 7

window.html 6 of 7

window.html 7 of 7

51

52

53 window Object

54 Using Cookies Cookie Cookie Data stored on user ’ s computer to maintain information about client during and between browser sessions Data stored on user ’ s computer to maintain information about client during and between browser sessions Can be accessed through cookie property Can be accessed through cookie property Set expiration date through expires property Set expiration date through expires property Use escape function to convert non-alphanumeric characters to hexadecimal escape sequences Use escape function to convert non-alphanumeric characters to hexadecimal escape sequences unescape function converts hexadecimal escape sequences back to English characters unescape function converts hexadecimal escape sequences back to English characters

cookie.html 1 of 4

cookie.html 2 of 4

cookie.html 3 of 4

59 In-Class Exercise #2 Modify the program given in pp to store the user ’ s name for only 1 minute. Modify the program given in pp to store the user ’ s name for only 1 minute. Hints: Hints: Use the mehtod toGMTSring() or toUTCSring() provided by JavaScript ’ s Date object to obtain the date for setting the expires property in the cookie. Use the mehtod toGMTSring() or toUTCSring() provided by JavaScript ’ s Date object to obtain the date for setting the expires property in the cookie.

60 Modifying the InnerText of a Paragraph <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" " " Modifying the InnerText of a Paragraph Modifying the InnerText of a Paragraph Click Refresh (or Reload) to run the script again Click Refresh (or Reload) to run the script again Put your homepage here. Put your homepage here. <!-- <!-- var msg; var msg; msg = window.prompt("Input the message:", "New Message"); msg = window.prompt("Input the message:", "New Message"); message.innerText = msg; message.innerText = msg; // --> // --> </html>

61 Final JavaScript Example Combines concepts discussed previously Combines concepts discussed previously

final.html 1 of 6

final.html 2 of 6

final.html 3 of 6

final.html 4 of 6

final.html 5 of 6

final.html 6 of 6

68

quiz2.html 1 of 3

quiz2.html 2 of 3

72

73 Web Resources g/js/tutorial/885.htm g/js/tutorial/885.htm