CIS 228 The Internet 11/17/11 Of Timers and Cookies.

Slides:



Advertisements
Similar presentations
Sue Wills July Objects The JavaScript language is completely centered around objects, and because of this, it is known as an Object Oriented Programming.
Advertisements

Lesson 4: Formatting Input Data for Arithmetic
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.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
JavaScript Forms Form Validation Cookies CGI Programs.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
CIS101 Introduction to Computing Week 10 Spring 2004.
CIS101 Introduction to Computing Week 10. Agenda Your questions Final exam and final project CIS101 Student Survey Class presentations: Your Mad Libs.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
Javascript and the Web Whys and Hows of Javascript.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT
JavaScript – Part II Data Types and Operations George Mason University June 3, 2010.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
JavaScript Part 1.
JavaScript Part 1.
Chapter 3 : Processing on the Front End JavaScript Technically its name is ECMA-262, which refers to the international standard which defines it. The standard.
Intro to JavaScript. Use the tag to tell the browser you are writing JavaScript.
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.
Computers and Scientific Thinking David Reed, Creighton University JavaScript and User Interaction 1.
1 JavaScript in Context. Server-Side Programming.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Using Client-Side Scripts to Enhance Web Applications 1.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
JavaScript - A Web Script Language Fred Durao
Basic Data Types Numbers (integer and floating point)‏ Strings (sequences of characters)‏ Boolean values (true/false)‏
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Variables and Data Types Data (information we're going to store) – Numbers – Text – Dates What types of data can JavaScript process? How do we store it?
05 – Java Script (1) Informatics Department Parahyangan Catholic University.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 JavaScript in Context. Server-Side Programming.
Java Script About Java Script Document Object Model Incorporating JavaScript Adding JavaScript to HTML Embedding a Javascript External Scripts Javascript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Variables.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
Tutorial 11 1 JavaScript Operators and Expressions.
CIS 228 The Internet Day 28, 12/13 Review. Alphabet Soup HTML (delineates document structure) HyperText Markup Language CSS (specifies document presentation)
CSC 121 Computers and Scientific Thinking Fall Event-Driven Programming.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
CIS 228 The Internet 12/6/11 Forms and Validation.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
COM621: Advanced Interactive Web Development Lecture 6 – JavaScript (cont.)
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
A variable is a name for a value stored in memory.
Chapter 6 JavaScript: Introduction to Scripting
“Under the hood”: Angry Birds Maze
JavaScript is a programming language designed for Web pages.
Web Development & Design Foundations with HTML5 7th Edition
Scope, Objects, Strings, Numbers
JavaScript.
14 A Brief Look at JavaScript and jQuery.
Objectives Insert a script element Write JavaScript comments
WEB PROGRAMMING JavaScript.
The Internet 12/8/11 JavaScript Review
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
The Internet 11/29/11 Functions
The Internet 11/15/11 Handling Data in JavaScript
The Internet 11/22/11 Conditionals and Loops
Tutorial 10 Programming with JavaScript
Tutorial 10: Programming with javascript
JavaScript: Introduction to Scripting
Presentation transcript:

CIS 228 The Internet 11/17/11 Of Timers and Cookies

Attaching JavaScript to XHTML element (in ) Attribute: type=“text/javascript” Attribute: src=“cookie.js” (JavaScript in a file) Event attributes of elements (in ) Attribute: onload=”action” Action executes when page loads Attribute: onclick=”action” Action executes when mouse clicks element Attribute: onblur=”action” Action executes when mouse stops hovering

JavaScript Functions Reusable chunks of code that accomplish common tasks Built in functions alert('hello world'); Displays text in a pop up window prompt('first message', 'second message'); Solicits data from user Example User defined functions Bundle together small tasks into bigger ones

More JavaScript Functions function touchRock() { var userName = prompt(“Your name is?” “Enter name.”); if (userName) { alert(“Hi, ” + userName); document.getElementById(“rockImg”).src = rock_happy.png; }

JavaScript Data Types String (text) ( e.g. “this is a string”, 'so is this', 'don\'t worry') Number Integer ( e.g., 23, 0, -37 ) Decimal ( e.g., , , ) Boolean true or false Object ( e.g., document )

JavaScript Locations Associate a name with a value Variable – the value may change Declaration: var s = “The user name is ”; Use: s = s + userName; Constant – the value is fixed Warning: constants are not supported by IE Declaration: const userName = “malcolmX”; Use: s = s + userName; Values have types; locations do not! Declarations should initialize locations

JavaScript Identifiers Identifiers name functions and locations Rules: 1 or more characters First character must be: letter or “_” or “$” All characters must be: letter or digit or “_” or “$” Spaces and other special characters are not allowed Camel case convention (for variables) thisIsACamelCaseVariableId Upper case convention (for constants) THIS_IS_AN_UPPER_CASE_CONSTANT_ID

JavaScript Expressions String operator: + (concatination) e.g., s + userName, “Bowen” + “ ” + “Alpern” Numeric operators: +, -, *, /, % e.g., 3+4, 3-4, 3*4, 3/4, 3%4, 3.14*r*r/2 Comparison operators: ==, !=,, >= e.g., 3+4 != 8, 4/2 == 2, userName == “malcolmX” Boolean operators: !, &&, || e.g., !done && ((3*x+7 2*x || x==0)) e.g., s==“done” || ! (name!=“Bowen” && s==“first”)

JavaScript Conversions Error values: undefined – uninitialized locations (always initialize) NaN – not a number (e.g., 'sam' / 3 == NaN ) Automatic conversions “12” / “6” == “12” / 6 == 12 / “6” == 12 / 6 == 2 “6” + “3” == “6” + 3 == 6 + “3” == “63” == 63 != == == = 5.14 Explicit conversions ParseInt(“6”) + parseInt(“3”) == == 9 ParseFloat(“3.14”) + 2 == 5.14

The document Object Can appear on either side of an assignment document (the root of the “DOM” object).getElementById(“x”) (the element with id=“x”).sytle (the style attribute of that element).height (the height of the element).color (the color of the element).getElementById(“i”) (and the element is img ).src (the URL of the file containing an image).getElementById(“f”) (and the element is a form field).value (the value entered in the field)

Timers One-time timers setTimeout(what, when); what – action to take ( e.g., “alert('wake up!');” ) when – time delay in milliseconds ( e.g., 5 * 60 * 1000 ) Repeating timers const timerId = setInterval(what, when); when – time between repeated actions Canceling repeating timers clearInterval(timerId);

Sizing Images The size (height) of the viewport document.body.clientHeight The size (height) of an image (with id=“im” ) document.getElementById(“im”).style.height Resizing an image when the page is resized onresize event attribute of

Cookies Medium-term persistent storage for small values List of name-value pairs (total size is browser dependent) Name is an identifier Value is a String Expiration date Helper functions (cookie.js) writeCookie(name, value, days); readCookie(name); eraseCookie(name); Not all browsers support cookies Navigator.cookiesEnabled