Introduction to JavaScript Objects, Properties, Methods.

Slides:



Advertisements
Similar presentations
Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
Advertisements

Essentials for Design JavaScript Level One Michael Brooks
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
The Web Warrior Guide to Web Design Technologies
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
JavaScript (Part 2) CS 183 4/13/2010. JavaScript (Part 2) Will cover: ◦ For.. In ◦ Events ◦ Try.. Catch, Throw ◦ Objects.
HTML Comprehensive Concepts and Techniques Second Edition Project 8 Integrating JavaScript with HTML.
Web Basics ISYS546. Basic Tools Web server –Default directory, default home page –Virtual directory Web page editor –Front Page Web page languages –HTML,
Javascript Document Object Model. How to use JavaScript  JavaScript can be embedded into your html pages in a couple of ways  in elements in both and.
Information Technology Center Hany Abdelwahab Computer Specialist.
CM143 - Web Week 2 Basic HTML. Links and Image Tags.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
 JavaScript is a programming language that web browsers understand. You can use it to make your web pages interactive by: Responding to user actions and.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 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.
1 CS101 Introduction to Computing Lecture 32 Event Handling (Web Development Lecture 11)
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. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
JavaScript and The Document Object Model MMIS 656 Web Design Technologies Acknowledgements: 1.Notes from David Shrader, NSU GSCIS 2.Some material adapted.
JavaScript - Document Object Model. Bhawna Mallick 2 Unit Plan What is DOM and its use? Hierarchy of DOM objects. Reflection of these objects in an HTML.
Server vs Client-side validation. JavaScript JavaScript is an object-based language. JavaScript is based on manipulating objects by modifying an object’s.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Dynamic Action with Macromedia Dreamweaver MX Barry Sosinsky Valda Hilley.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
1 CS101 Introduction to Computing Lecture 18 Objects, Properties, Methods (Web Development Lecture 6)
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JavaScript Part 1.
1 VU. 2 CS101 Introduction to Computing Lecture 15 More on Interactive Forms (Web Development Lecture 5)
Introduction to JavaScript + More on Interactive Forms.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
1 CS428 Web Engineering Lecture 11 Client Side Scripting (JavaScript - I)
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
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.
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.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Scripting Language A scripting language or script language is a programming language that supports the writing of scripts. The term script is typically.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Introduction to JavaScript 41 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 17.
JavaScript. During the last lecture We looked at the utility of forms on Web pages We found out about the various components that are used in a form We.
JavaScript - A Web Script Language Fred Durao
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
Introduction to JavaScript CS101 Introduction to Computing.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
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.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
Form Processing Week Four. Form Processing Concepts The principal tool used to process Web forms stored on UNIX servers is a CGI (Common Gateway Interface)
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
INTRODUCTION JavaScript can make websites more interactive, interesting, and user-friendly.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
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.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
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.
JavaScript JavaScript is a programming language that web browsers understand. You can use it to make your web pages interactive by: Responding to user.
Copyright © Terry Felke-Morris Web Development & Design Foundations with HTML5 8 th Edition CHAPTER 14 KEY CONCEPTS 1 Copyright.
Introduction to.
JavaScript is a programming language designed for Web pages.
Donna J. Kain, Clarkson University
Web Development & Design Foundations with HTML5 7th Edition
14 A Brief Look at JavaScript and jQuery.
During the last lecture we continued our discussion on Interactive Forms
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
JavaScript Basics What is JavaScript?
Presentation transcript:

Introduction to JavaScript Objects, Properties, Methods

Today’s Lecture … We will have a more formal introduction to JavaScript and client-side scripting We will become able to appreciate the concept of objects in JavaScript We will learn about the properties of those objects, and about how to read & modify them We will become able to perform simple tasks through the application of methods

Last time we looked at two distinct ways of performing the “form” field checking function. From now onwards, we will be employing the 2 nd way more often than not In that 2 nd way, we referred to a function in the HTML BODY, and but defined that function in the HTML HEAD

The main code segment that goes between the, tags in the HEAD : function checkForm() { if ( document.send .sender.value.length < 1) { window.alert( “Empty From field! Please correct” ); } The JavaScript code included as an attribute of the “Send ” button: onMouseOver=“checkForm()”

Send an function checkForm(){ if (document.send .sender.value.length Send an From: To: Subject: Message:

Some of things that JavaScript cannot do! The following file operations on the client computer: –Read-- Modify –Rename-- Delete –Create Create graphics (although, it does have the ability to format pages through HTML - including the placement of graphics) Any network programming bar one function: the ability to download a file to the browser specified through an arbitrary URL

Some of the things that JavaScript can do! 1.Control the appearance of the browser 2.Control the content and appearance of the document displayed in the browser 3.Interact with the user through event handlers 4.Arbitrary calculations, including floating-point ones 5.Store & modify a limited amount of data about the user in the form of client-side “cookies”

Client-Side JavaScript Although a version of JavaScript exists that can be used to write server-side scripts, our focus in this course will only be on client-side scripting

Case Sensitivity HTML is not case sensitive. The following mean the same to the browser: – -- JavaScript is case sensitive. Only the first of the following will result in the desired function – the rest will generate an error or some other undesirable event: –onMouseClick-- OnMouseClick –onmouseclick-- ONMOUSECLICK

JavaScript A programming language specifically designed to work with Web browsers It is designed to be used for developing small programs – called scripts – that can be embedded in HTML Web pages JavaScript: –Is an interpreted language –Supports event-driven programming –Is object-based

JavaScript is Object-Based Everything that JavaScript manipulates, it treats as an object – e.g. a window or a button An object has properties – e.g. a window has size, position, status, etc. Objects are modified with methods that are associated with that object – e.g. a resize a window with resizeTo(150, 200)

Properties Objects may have a single or several properties A property may have one of the following values: –Number-- Text-- Boolean –Array-- Functions –Objects (Example: “document” – a property of the “window” object – is an object in itself. A “document” in turn may contain a “form” object as a property, and then that “form” may contain a “button” property, which, once again, is an object in itself)

Referring to a Property objectName.propertyName Examples: window.width button.value dot

Change Property Demo # 1 function changeStatus() { window.status = “Mouse has touched the button”; } Change Property Demo # 1

The main code segment that goes between the, tags in the HEAD : function changeStatus() { window.status=“Mouse has touched the button”; } The JavaScript code included as an attribute of the “Submit” button: onMouseOver=“changeStatus()” propert y new value

The main code segment that goes between the, tags in the HEAD : function gotoUrl() { window.location=“ } The JavaScript code included as an attribute of the “Go to IMT” button: onMouseOver=“gotoUrl()” propert y new value

A Suggestion Please try the pieces of code that I just demonstrated to you to change the status and location properties of the “window” object yourself Also try changing the width, height properties of the “window” object

Types of Objects JavaScript –Objects that are part of JavaScript –Examples: window, document Browser –Objects that contain info not about the contents of the display, but the browser itself –Examples: history, navigator User-defined

One More Example: Let us try to change the background color of the window

The main code segment that goes between the, tags in the HEAD : function changeBgColor() { window.document.bgColor = “pink”; } The JavaScript code included as an attribute of the “Change Color” button: onMouseOver=“changeBgColor()” propert y new value

In addition to “bgColor”, there are many other properties of the “document” object, e.g. fgColor linkColor title URL referrer lastModified cookie forms[ ] images[ ] links[ ] …

We have learnt how to modify the properties of objects But the properties are not there just so that we can modify them; we can also just read them – that is just find out their current value Let us now look at an example where we first read a property, display the current value, and then change the property

The main code segment that goes between the, tags in the HEAD : function changeBgColor() { oldColor = window.document.bgColor; window.document.bgColor = “pink”; window.alert("The old color was " + oldColor); } The JavaScript code included as an attribute of the “Change Color” button: onMouseOver=“changeBgColor()”

Now we have established what we mean by objects: a named collection of properties and methods And that JavaScript treats everything that it manipulates as an object We have also learnt how to change the properties of these objects by selecting a property and equating it to a new value

Methods: Functions (code, instructions, behavior) associated with objects Methods are functions associated with an object that can be used to manipulate that object Example: –window.close() –Here “close()” is a method that has been defined for the “window” object. Its function is to close the “window”

Referring to a Method objectName.methodName( argumnet1 ) Examples: window.close() button.click() dot Info is passed on to the method through arguments

A few more methods associated with the “window” object alert() confirm() prompt() close() open() focus() blur() setTimeOut()

The main code segment that goes between the, tags in the HEAD : function imtWindow() { window.open(“ } The JavaScript code included as an attribute of the “New IMT Window” button: onClick=“imtWindow()” method argument different event handler

Event Handlers Objects are made up of properties and associated methods Many objects also have “event handlers” associated with them “Events” are actions that occur as a result of user’s interaction with the browser We use “event handlers” [e.g. onMouseOver(), onClick()] to design Web pages that can react to those events More on event handlers in a future lecture

During Today’s Lecture … We had a more formal introduction to JavaScript and client-side scripting We became able to appreciate the concept of objects in JavaScript We learnt about the properties of those objects We also became able to perform simple tasks through the application of methods