COP3530- Data Structures Javascript

Slides:



Advertisements
Similar presentations
Molecular Biomedical Informatics Web Programming 1.
Advertisements

JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
The Document Object Model (DOM) 1 JavaScript is an object-based language—that is, it’s based on manipulating objects by changing each object’s properties.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
HTML 5 and CSS 3, Illustrated Complete Unit L: Programming Web Pages with JavaScript.
AJAX (Asynchronous JavaScript and XML) Amit Jain CS 590 – Winter 2008.
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.
JavaScript Programming Basics Chapter What is Programming?
Introduction to JavaScript 11 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 14.
HTML DOM.  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  The DOM presents an HTML document as a tree- structure.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
© 2000 – All Rights Reserved - Page 1 Introduction to JavaScript Programming Part Two.
JavaScript Lecture 6 Rachel A Ober
DOM and JavaScript Aryo Pinandito.
JavaScript is a client-side scripting language. Programs run in the web browser on the client's computer. (PHP, in contrast, is a server-side scripting.
Arrays – What is it? – Creation – Changing the contents Functions – What is it? – Syntax – How they work – Anonymous functions A quick lesson in Objects.
Functions and Objects. First Midterm exam Date: October 8, 2008 Content: Two parts: On-paper:Multiple choices On-computer: Write codes Cover everything.
Tutorial 2 Variables and Objects. Working with Variables and Objects Variables (or identifiers) –Values stored in computer memory locations –Value can.
Manipulating the DOM CST 200 – JavaScript 3 –
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
A Quick Introduction to d3.js & Reusable Charts Adam Pere Olin College, November 11 th 2014
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 10.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
Chapter 10: JavaScript Functions CIS 275—Web Application Development for Business I.
Event-Driven Programming Chapter Page Section: Section or division of an HTML page Generic block element Example: What's the difference between.
Review of the DOM Node properties and methods Some ways of accessing nodes Appending, copying and removing nodes Event handling – Inline – Scripting –
CS50 Week 9 Sam Green ’
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
Introduction to Programming and JavaScript. Programming.
JavaScript Overview Developer Essentials How to Code Language Constructs The DOM concept- API, (use W3C model) Objects –properties Methods Events Applications;
School of Computing and Information Systems CS 371 Web Application Programming JavaScript - DOM Modifying the Page from within.
1 Javascript CS , Spring What is Javascript ? Browser scripting language  Dynamic page creation  Interactive  Embedded into HTML pages.
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
Understanding JavaScript and Coding Essentials Lesson 8.
Document Object Model (DOM). Outline  Introduction of DOM  Overview of DOM  DOM Relationships  Standard DOM.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
MTA EXAM HTML5 Application Development Fundamentals.
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 Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
JAVASCRIPT A quick review. True False ■The DOM is a standardized way of referring to parts of a Web page. ■TRUE ■In the DOM, attributes have their own.
Web Programming JavaScript Essentials. Document Object Model Essentials Object Properties To put somenew text into a text box object, you assign a string.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
Java Script and the DOM DOM stands for: –The Document Object Model When a browser reads a web page, it converts it’s contents from HTML into a hierarchical.
REEM ALMOTIRI Information Technology Department Majmaah University.
Build in Objects In JavaScript, almost "everything" is an object.
Java Script Introduction. Java Script Introduction.
Javascript and Dynamic Web Pages: Client Side Processing
Programming Web Pages with JavaScript
Week 3: Introduction to Javascript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
CS 371 Web Application Programming
A little MORE on JavaScript
Javascript Short Introduction By Thanawat Varintree,
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Introduction to Programming the WWW I
DHTML.
JavaScript Introduction
Event Driven Programming & User Defined Functions
Functions, Regular expressions and Events
Web Design and Development
JavaScript Overview By Kevin Harville.
JavaScript Basics Topics Review Important Methods Writing Functions
Web Programming and Design
Web Programming and Design
Web Programming and Design
Presentation transcript:

COP3530- Data Structures Javascript Dr. Ron Eaglin

Objectives Understand the Document Object Model (DOM) and how it works with JavaScript Know how to get input from the DOM in JavaScript Understand how to present output to the DOM Write functions in JavaScript Execute JavaScript functions from the DOM Create objects in JavaScript Extend objects in JavaScript

Overview JavaScript allows for the manipulation of HTML documents (among other things) HTML documents follow the Document Object Model (DOM) All elements in an HTML document can be accessed and manipulated The access to these elements (objects) is through the DOM

Document Object Model This is the Document

Accessing the Document Contents of the document are added as html code (there are other methods) <input type=‘button’ id=‘myButton’ value=‘A Button’ />

Accessing the Document In JavaScript the element can be accessed in code var aButton = document.getElementById(‘myButton’); document is the Document object (global scope) getElementById is a function supported by the Document aButton is the object created in JavaScript.

Events <input type=‘button’ id=‘myButton’ value=‘A Button’ onclick=‘changeValue()’/> onclick is a supported event in the DOM changeValue() is a JavaScript function

Writing a JavaScript function function changeValue() { var aButton = document.getElementById('myButton'); aButton.value = "Changed Button Value"; }

Some Review HTML – language for web pages DOM – Document Object Model – the “page” is referred to as the global object document and is accessible in JavaScript Objects can be added to the document (using html) These objects can be accessed in code document.getElementById() You can write functions using JavaScript to perform tasks You can trigger the execution of these objects using events - onclick

Creating an Object Everything in JavaScript is an object In JavaScript a function is an object We can create objects using this var anObject = function() { this.anInteger = 0; this.aString = "Hi"; }

Creating an Object var MyObject = function() { this.anInteger = 0; this.aString = "Hi"; } This defines the object and the properties of the object – it does not create an instance of the object. This is simply a definition.

Creating an Object function changeValue() { var aButton = document.getElementById('myButton'); var anObject = new MyObject(); alert(anObject.anInteger); aButton.value = anObject.aString; } var anObject = new MyObject(); <- This makes an object

Creating Object alert(anObject.anInteger);

Using Objects

Extending Objects - prototype MyObject.prototype.aFunction = function(anArg) { return "Prototype Function with Argument " + anArg; } function changeValue() { var aButton = document.getElementById('myButton'); var anObject = new MyObject(); aButton.value = anObject.aFunction("Sample Argument");

Extending Objects

Review In JavaScript – everything is an Object You can create objects simply by defining a function and assigning it a name You can extend that object using the prototype keyword. You MUST instantiate objects to use them.

JavaScript Output <div id="output"> </div> (or use paragraph) <p id=“output> </p> function changeValue() { var aDiv = document.getElementById('output'); var anObject = new MyObject(); aDiv.innerHTML = anObject.aFunction("Sample Argument"); }

Output to Document

Other Properties function changeValue() { var aDiv = document.getElementById('output'); var anObject = new MyObject(); aDiv.innerHTML = anObject.aFunction("Sample Argument"); aDiv.style="color:blue; background-color: yellow;"; }

Results Changing Properties

Objectives Understand the Document Object Model (DOM) and how it works with JavaScript Know how to get input from the DOM in JavaScript Understand how to present output to the DOM Write functions in JavaScript Execute JavaScript functions from the DOM Create objects in JavaScript Extend objects in JavaScript