1 HCI 201 JavaScript - Part 1. 2 Static web pages l Static pages: what we have worked with so far l HTML tags tell the browser what to do with the content.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Introducing JavaScript
1 COMM 1213 H1 COMP 4923 X1 JavaScript 1 (Readings: Ch. 10, 11 Knuckles)
The Web Warrior Guide to Web Design Technologies
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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Tutorial 10 Programming with JavaScript
CIS101 Introduction to Computing Week 09. Agenda Hand in Resume project Your questions Introduction to JavaScript This week online Next class.
Tutorial 11 Working with Operators and Expressions
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
CIS101 Introduction to Computing Week 09 Spring 2004.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Introduction to scripting
JavaScript Events and Event Handlers 1 An event is an action that occurs within a Web browser or Web document. An event handler is a statement that tells.
Javascript and the Web Whys and Hows of Javascript.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
What is Java Script? An extension to HTML. An extension to HTML. Allows authors to incorporate some functionality in their web pages. (without using CGI.
Chapter 4 JavaScript and Dynamic Web pages. Objectives Static Web pages Dynamic Web pages JavaScript Variables Assignments. JavaScript Functions –(prompt(“”,””)
1 JavaScript in Context. Server-Side Programming.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
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.
1 A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 4 JavaScript and.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 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.
Web111a_chapt08.ppt HTML: Section 8 JavaScript CGI Programs (Server Side programs) Common Gateway Interface Run on server Communicate with user across.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 JavaScript in Context. Server-Side Programming.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Tutorial 11 1 JavaScript Operators and Expressions.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
1 JavaScript and Dynamic Web Pages Lecture 7. 2 Static vs. Dynamic Pages  A Web page uses HTML tags to identify page content and formatting information.
REEM ALMOTIRI Information Technology Department Majmaah University.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Chapter 6 JavaScript: Introduction to Scripting
Tutorial 10 Programming with JavaScript
JavaScript is a programming language designed for Web pages.
Introduction to Scripting
JavaScript.
WEB PROGRAMMING JavaScript.
Chapter 4 JavaScript and Dynamic Web Pages
T. Jumana Abu Shmais – AOU - Riyadh
Tutorial 10 Programming with JavaScript
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
JavaScript is a scripting language designed for Web pages by Netscape.
JavaScript: Introduction to Scripting
Presentation transcript:

1 HCI 201 JavaScript - Part 1

2 Static web pages l Static pages: what we have worked with so far l HTML tags tell the browser what to do with the content l Pages don’t change during viewing l Like reading a book or magazine

3 Dynamic web pages l Display or behavior can change during viewing l Can prompt for entry of information l Can store information in memory l Display can incorporate user’s input or the result of computations A fun example A fancy example

4 What is JavaScript? JavaScript is NOT Java …more details… JavaScript is NOT Javamore details JavaScript is an interpreted web scripting language run from the Web browser. JavaScript is the scripting language of choice for creating interactive web pages.

5 Key differences Java/JavaScript  Java is a full-blown programming language; JavaScript is a limited scripting language.  Java is relatively complex; JavaScript is usually easier to learn.  Java must be compiled and interpreted; JavaScript needs only to be interpreted.  Java makes larger files and is slower on the Internet; JavaScript creates smaller files and is faster.  Java can run without a browser; JavaScript requires a browser... it works only in a WWW environment.  Java Applets are applications designed specifically for the WWW.

6 JavaScript is coded within HTML documents JavaScript example yourname = prompt("Please enter your name", ""); document.write("Hello " + yourname + ", and welcome !"); I hope you will enjoy learning JavaScript. Download pic to try this example. javascript.jpgjavascript.jpg This script is in the html body

7 Prompt window

8

9 Look at the script closer… yourname = prompt("Please enter your name", ""); document.write("Hello " + yourname + ", and welcome !");

10 Prompt statement yourname = prompt("Please enter your name", ""); Your message

11 Prompt statement yourname = prompt("Please enter your name", ""); Default entry value

12 Prompt statement yourname = prompt("Please enter your name", “Joe"); Default entry value

13 Write statement document.write("Hello " + yourname + ", and welcome !"); l Forms a text string given to the browser for processing

14 Write statement document.write("Hello " + yourname + ", and welcome !"); l Forms a text string given to the browser for processing l + concatenates (joins) strings and variables

15 Write statement document.write("Hello " + yourname + ", and welcome"); l Forms a text string given to the browser for processing l + concatenates (joins) strings and variables l String can contain HTML tags!

16 Common errors… document.write("Hello " + yourname + ", and welcome !"); l Missing quote marks l Misspelled reserved words l With Internet Explorer, turn on detailed error reporting with: Tools > Internet Options > Advanced and click on: Display a notification about every script error

17 Keep in mind … JavaScript is case sensitive. Each JavaScript command line must end with a semi-colon (;) One-line comment: // comment Multi-line comment: /* comment */

18 Variables l A variable is a named element in a program, used to store and retrieve information l Name must start with a letter l Case sensitive: “A” and “a” are different! l No space allowed in name l No “special characters” like $ or # l Underscore is OK to join parts of name.

19 Variables l When you have more than one word in a variable name, start with a lowercase first letter and capitalize the first letter of any subsequent word. Ex: currentDate

20 Valid variable names l tempInFahr l temp_in_fahrenheit l TEMP_IN_FAHR l SUM l current_age l Sum2Date

21 Invalid variable names l $pay_amount l 2hotForU l Count# l count of widgets l final $ not valid in name Can’t start with a digit # not valid in name Reserved word Blanks in name

22 Reserved words (Pg. 63)

23 Hiding JavaScript from old browsers Within the tag, include HTML comment lines such as: script commands and comments <!- - Hide this script from browsers that don’t support JavaScript // Stop hiding from other browsers - -> When a Web browser that doesn’t support scripts encounters this code, it ignores the content of the tag.

24 Components of JavaScript Objects (hierarchy, dot syntax) Instance Properties Values Events and Event Handlers Variables Arrays Methods Operators (Assignment, Comparison, etc.) Functions Example

25 Types of variables Numeric: 13, 22.3, , 5.1E2 (5.1x10 2 ) String: any group of characters within quotation marks. “This is a string”, ‘another string’, ‘3.14’, “” (the empty string) Boolean: can only be true or false var isOk = true;

26 Creating a Date object JavaScript doesn’t have a Date data type. You need to create a date object that contains date information. dateVariable = new Date(“month, day, year, hours:minutes:seconds”); or dateVariable = new Date(year, month, day, hours,minutes,seconds); Examples: taxDay = new Date (“April, 15,2005,24:0:0”); or taxDay = new Date (2005,3,15,24,0,0); today= new Date ();

27 Time in JavaScript Seconds and minutes: 0-59 Hours:0-23 Week Days:0 (Sunday) – 6 (Saturday) Day: 1-31 (day of the month) Months:0 (January) –11 (December) Year: since 1900 Time: in millisecond since 6 p.m on 12/31/69 Example: taxDay = new Date(2005,15,3,0,0,0);

28 Date methods For retrieving date and time value dateVariable.getFullYear(); dateVariable.getMonth(); dateVariable.getDate(); dateVariable.getDay(); dateVariable.getHours(); dateVariable.getMinutes(); dateVariable.getSeconds(); taxDay.getMonth(); //returns 3 taxDay = new Date (2005,15,3,0,0,0); Example ThisMonth = Today.getMonth()+1;

29 Working with Expressions and Operators Expressions are JavaScript commands that assign values to variables.  Example: use the expression, daysLeft=999, to assign the value 999 to the daysLeft variable Expressions are created using variables, values, and operators. One of the most commonly used operators is the + operator, which performs the action of adding or combining two elements.  Example: use the plus operator in a program with the following command: var ThisMonth = Today.getMonth()+1;

30 Addition and Concatenation result = var1 + var2 If both are number variables:  Adds var1 to var2  Assigns the result to the variable result  result is a number variable If at least one of the two is a string:  Concatenate var1 and var2  Assigns the result to the variable result  result is a string variable