A (gentle???) Introduction to JavaScript

Slides:



Advertisements
Similar presentations
JavaScript and AJAX Jonathan Foss University of Warwick
Advertisements

JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
Lesson 12- Unit L Programming Web Pages with JavaScript.
Introduction to JavaScript Module 1 Client Side JS Programming M-GO Sponsored By
The Web Warrior Guide to Web Design Technologies
1 Javascrbipt Intro Javascript (or js) is a programming language. Interpreted, not compiled. Not the same as java, but, similar. Use tags to use. Object-oriented.
Computer Science 103 Chapter 4 Advanced JavaScript.
Inline, Internal, and External FIle
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.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
1 A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 4 JavaScript and.
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
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.
JavaScript Challenges Answers for challenges
INTRODUCTION JavaScript can make websites more interactive, interesting, and user-friendly.
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.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Introduction to AJAX MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/4/2016.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
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.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
Programming Web Pages with JavaScript
Applied Component I Unit II Introduction of java-script
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Learning to Program D is for Digital.
Scripting the DOM MIS 3502, Fall 2016 Jeremy Shafer Department of MIS
© 2015, Mike Murach & Associates, Inc.
Class06 Arrays MIS 3502 Jeremy Shafer Department of MIS
Intro to JavaScript CS 1150 Spring 2017.
Introduction to AJAX MIS 3502 Jeremy Shafer Department of MIS
Introduction to JavaScript
HTML Forms and User Input
Introduction to AJAX MIS 3502 Jeremy Shafer Department of MIS
Arrays MIS 3502 Jeremy Shafer Department of MIS Fox School of Business
A second look at JavaScript
T. Jumana Abu Shmais – AOU - Riyadh
Functions, Regular expressions and Events
JavaScript and the DOM MIS 2402 Jeremy Shafer Department of MIS
An Introduction to Animation
MIS JavaScript and API Workshop (Part 2)
An Introduction to JavaScript
Programming Control Structures with JavaScript Part 2
Getting started with jQuery
An introduction to jQuery
Loops and Arrays in JavaScript
JavaScript objects, functions, and events
Recognizing JavaScript Features
Tonga Institute of Higher Education IT 141: Information Systems
Introduction to JavaScript
An introduction to jQuery
Tonga Institute of Higher Education IT 141: Information Systems
Introduction to Programming and JavaScript
An introduction to jQuery
Introduction to AJAX and JSON
CNIT 133 Interactive Web Pags – JavaScript and AJAX
HTML MIS 2402 Jeremy Shafer Department of MIS Fox School of Business
Web Programming and Design
Web Programming and Design
Web Programming and Design
Introduction to Web programming
JavaScript – Let’s Draw!
JavaScript and the DOM MIS 2402 Maxwell Furman Department of MIS
Presentation transcript:

A (gentle???) Introduction to JavaScript Jeremy Shafer Department of MIS Fox School of Business Temple University

Objects are described by their: Before we begin… Recall that the world around us is made up of things. We call those things: nouns, entities or … OBJECTS. Objects are described by their: properties and methods.

Let’s think of an example: a bedroom. If this is a representation of a bedroom, what would it’s properties (also called attributes) be? Would this room have any methods?

Our example extended: an apartment. This is an apartment. It has some properties that a room does not have. But … it also has two bedrooms contained in it. Apparently, this object holds (at least) two objects inside it.

Our example continued. This is one floor of an apartment building. If you look closely you will determine that it is really made up of individual apartments.

This is an apartment building. It is made up of floors. But wait there’s more… This is an apartment building. It is made up of floors.

What if we wanted to express this electronically? <apartment_building> <floor> <apartment> <bedroom></bedroom> </apartment> etc. etc. etc. </floor> <floor> etc. etc. etc. </floor> etc. etc. etc. </apartment_building>

<apartment id=“Apartment305”> <bedroom></bedroom> Finding a bed room If we wanted to find a room in our building, I suppose we could give directions: Go to the building. Go up the stairs, one floor at a time, count the floors until you get to 3. Now go down the hall, count the apartments one at a time, until you get to 5. Now find the first bedroom in the apartment. Congratulations. You found apartment 305, bedroom 1. You know what would make these instructions easier? An identifier. Go to the building. Go to apartment 305. enter bedroom 1. <apartment id=“Apartment305”> <bedroom></bedroom> </apartment>

Taking action on an object The prior slide illustrated a (completely imaginary) syntax for describing our apartment buildings objects as they are. But, what if we wanted to take action on those objects? What if, instead of an unchanging blueprint of our apartment building we wanted a working model of it? How would we, for example, lock a door? Still mostly imaginary syntax! Unlock the door to an apartment: building.getElementById(“Apartment305”).unlock(); Unlock the door to a room: var theApt = building.getElementById(“Apartment305”); //get the apartment var theRooms = theApt.getElementsByTagName(“bedroom”); //get all the // bedrooms in the apartment theRooms[“0”].unlock(); //unlock the first bedroom door

Thinking about it… Are all rooms the same? Are there other actions that we might want to take on a room? Since our model is electronic, we can change lots of things that may (or may not) make sense in the real world. How about this…. is this a room?

So... Here’s a big idea. Our HTML documents are really objects. They are composite objects made up of smaller objects. JavaScript is a powerful language, similar in syntax to PHP, that lets us manipulate those objects.

Some basic JavaScript Syntax We need some basic JavaScript syntax to get started. We’ll add more as time goes by. Syntax Comment <script></script> This is the script tag. For the most part, all our JavaScript goes in here. This is where our browser (FireFox, Chrome) expects it all to be. alert('some message here); Probably the easiest JavaScript command. This command will cause the browser to display a message box. It is not really used much in real life, but it is a helpful function for learning. onclick The onclick event - most HTML elements have the onclick attribute. We use this attribute to specify what happens when a HTML element is clicked. function() { } JavaScript uses a lot of functions. In JavaScript, functions can be named, or anonymous. For the most part, we will used anonymous functions. "use strict"; This is a direction we give to the browser, telling us how JavaScript should be evaluated. The "use strict" directive is recommended to any person learning JavaScript, and is generally preferred by professional coders. window.onload The onload event - this event will specify what should happen when the window is done being loaded. document.getElementById("some_id") The document object has a really handy method called getElementById. It will return a reference to one specific html tag. .innerHTML Most HTML tags hold some text. This text is referred to as the innerHTML of the tag. We can use this to reassign the contents of an individual tag and those changes take place immediately. There's no need to reload the entire page in order to see the change. .value HTML input tags can have a value. We can use the .value property to get and set the value of an HTML input tag.

Let’s play!