Outline. Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages

Similar documents
CGS 3066: Spring 2015 JavaScript Reference

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript CS 4640 Programming Languages for Web Applications

CISC 1600 Lecture 2.4 Introduction to JavaScript

<form>. input elements. </form>

Introduction to JavaScript

What is Java Script? Writing to The HTML Document. What Can JavaScript do? CMPT 165: Java Script

Working with JavaScript

JavaScript s role on the Web

CHAPTER 6 JAVASCRIPT PART 1

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

JavaScript: The Basics

Session 16. JavaScript Part 1. Reading

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Session 6. JavaScript Part 1. Reading

Lecture 14. Introduction to JavaScript. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

INFS 2150 Introduction to Web Development and e-commerce Technology. Programming with JavaScript

Objectives. Introduction to JavaScript. Introduction to JavaScript INFS Peter Y. Wu, RMU 1

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies

JavaScript is described in detail in many books on the subject, and there is excellent tutorial material at

Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains 2 components

JavaScript by Vetri. Creating a Programmable Web Page

E ECMAScript, 21 elements collection, HTML, 30 31, 31. Index 161

Developing Ajax Web Apps with GWT. Session I

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 11

INF5750. Introduction to JavaScript and Node.js

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

CSC Web Programming. Introduction to JavaScript

CIW 1D CIW JavaScript Specialist.

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

JavaScript: Introduction, Types

Getting Started with

JavaScript and Ajax.

The first sample. What is JavaScript?

UNIT -II. Language-History and Versions Introduction JavaScript in Perspective-

UNIT 3 SECTION 1 Answer the following questions Q.1: What is an editor? editor editor Q.2: What do you understand by a web browser?

This course is designed for web developers that want to learn HTML5, CSS3, JavaScript and jquery.

Working with Javascript Building Responsive Library apps


Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains an Individual and Group component

JavaScript I Language Basics

Client vs Server Scripting

JavaScript: Introductionto Scripting

Client-Side Web Technologies. JavaScript Part I

v0.9.3 Tim Neil Director, Application Platform & Tools Product

HTML CS 4640 Programming Languages for Web Applications

Master Project Software Engineering: Team-based Development WS 2010/11

Chapter 17. Fundamental Concepts Expressed in JavaScript

JavaScript. The Bad Parts. Patrick Behr

Webinar. The Lighthouse Studio Scripting Series. JavaScript Sawtooth Software, Inc.

SEEM4570 System Design and Implementation Lecture 03 JavaScript

AJAX Programming Chris Seddon

Frontend II: Javascript and DOM Programming. Wednesday, January 7, 15

Tutorial 10: Programming with JavaScript

5/19/2015. Objectives. JavaScript, Sixth Edition. Introduction to the World Wide Web (cont d.) Introduction to the World Wide Web

Produced by. App Development & Modeling. BSc in Applied Computing. Eamonn de Leastar

Web-based IDE for Interfacing View Controller

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) What is JavaScript?

JavaScript: Getting Started

Chapter 2 Working with Data Types and Operators

Why Use A JavaScript Library?

JavaScript: The Definitive Guide

Lecture 3: The Basics of JavaScript. Background. Needs for Programming Capability. Origin of JavaScript. Using Client-side JavaScript

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

Frontend guide. Everything you need to know about HTML, CSS, JavaScript and DOM. Dejan V Čančarević

CSS & Troubleshooting IE6

COURSE OUTLINE MOC 20480: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

CISH-6510 Web Application Design and Development. Overview of JavaScript. Overview

UI Course HTML: (Html, CSS, JavaScript, JQuery, Bootstrap, AngularJS) Introduction. The World Wide Web (WWW) and history of HTML

Chapter 3 - Simple JavaScript - Programming Basics. Lesson 1 - JavaScript: What is it and what does it look like?

COSC 122 Computer Fluency. Programming Basics. Dr. Ramon Lawrence University of British Columbia Okanagan

Syllabus - July to Sept

Varargs Training & Software Development Centre Private Limited, Module: HTML5, CSS3 & JavaScript

JavaScript: Introduction to Scripting

Creating an Online Catalogue Search for CD Collection with AJAX, XML, and PHP Using a Relational Database Server on WAMP/LAMP Server

Chapter 4 Basics of JavaScript

1. Setup a root folder for the website 2. Create a wireframe 3. Add content 4. Create hyperlinks between pages and to external websites

JavaScript Doesn't Have to Hurt: Techniques, Tools and Frameworks to Ease JavaScript Development

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

Web Development & Design Foundations with HTML5

CSS The web browser uses its own resources, and eases the burden on the server. It has fewer features than server side scripting.

State of the Open Web. Brad Neuberg, Google

grabattention The jquery Plug-in

The course is supplemented by numerous hands-on labs that help attendees reinforce their theoretical knowledge of the learned material.

MODULE 2 HTML 5 FUNDAMENTALS. HyperText. > Douglas Engelbart ( )

Documents and computation. Introduction to JavaScript. JavaScript vs. Java Applet. Myths. JavaScript. Standard

CS312: Programming Languages. Lecture 21: JavaScript

JavaScript Introduction

JavaScript Lecture 1

COPYRIGHTED MATERIAL. Contents. Chapter 1: Creating Structured Documents 1

Q1. What is JavaScript?

EXERCISE: Introduction to client side JavaScript

JScript Reference. Contents

Why Discuss JavaScript? CS312: Programming Languages. Lecture 21: JavaScript. JavaScript Target. What s a Scripting Language?

Chapter4: HTML Table and Script page, HTML5 new forms. Asst. Prof. Dr. Supakit Nootyaskool Information Technology, KMITL

Programing for Digital Media EE1707. Lecture 3 JavaScript By: A. Mousavi and P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Web Site Design and Development JavaScript

JAVASCRIPT FOR PROGRAMMERS

Overview

a Why JavaScript? jonkv interactivity on the web CGI JavaScript Java Applets Netscape LiveScript JavaScript 1: Example

Transcription:

JavaScript CMPT 281

Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages

Announcements

Layout with tables Assignment 3

JavaScript Resources

Resources

Why JavaScript?

HTML + CSS + JavaScript

Separation of Concerns

Separation of Concerns

What is Javascript?

What is Javascript? A scripting programming language Cannot be run without a browser Embedded in most web browsers A way to create web pages that respond dynamically to user action A tool for server-side development

Types of computer languages High-Level vs. Low Level Compiled vs. Interpreted Structured vs. Object Oriented Scripting vs. Programming

JavaScript High-Level vs. Low Level Compiled vs. Interpreted Structured vs. Object Oriented Scripting vs. Programming

History Need for client side interaction Code executes on the local machine No need for network connection once script runs Developed by Netscape in 1995 (Not related to the Java Language) Actually ECMAScript (ECMA-262) en.wikipedia.org/wiki/ecmascript Several variants (JScript, Action Script )

What can JavaScript do? It is a full programming language API (application programming interface) is specific to working with browsers Restrictions: Security-based limitations No networking No access to local file system Limited UI toolkit and graphics (This is changing with HTML5)

What can JavaScript do? Benefits: Close integration with the browser Access the webpage and all elements within Adjust or create HTML Open and resize browser windows Run animations, play sounds

Example: writing to the page

Example: loading a random image

Where do scripts go? In the HMTL page Like styles, can be external, internal, or inline Use these for different situations

Where do scripts go? For scripts that respond to user events, and for functions: Either external or internal In <head> </head> For scripts that write document content: In <body> </body>

Body example <html> <head> </head> <body> <script type="text/javascript"> document.write("this message written by JavaScript"); </script> </body> </html>

Internal example <html> <head> <script type="text/javascript"> function message() { alert("this alert was called with the onload event"); } </script> </head> <body onload="message()"> </body> </html

External example <html> <head> <script type="text/javascript" src="xyz.js"></script> </head> <body> </body> </html>

How does JS access the page? DOM: Document Object Model A framework to describe a web page (document) in a tree-like structure

DOM

DOM

Using the DOM to get at the page <html> <body> <p id="intro">hello World!</p> <script type="text/javascript"> x=document.getelementbyid("intro"); document.write(x.firstchild.nodevalue); </script> </body> </html>

Using the DOM to get at the page <html> <body> <p id="intro">hello World!</p> <script type="text/javascript"> x=document.getelementbyid("intro"); document.write(x.firstchild.nodevalue); </script> </body> </html>

JavaScript Basics

JavaScript Basics Statements Variables Events Functions Dialogs

Statements <script type="text/javascript"> var a = 10; var b = 11; var c; c = a + b; alert( The answer is + c); </script>

JavaScript Variables Variables are used to store data. Rules for variable names: Variable names are case sensitive They must begin with a letter or the underscore character strname STRNAME (not same)

JavaScript Variables Variables: containers for data All variables have Name Type JavaScript is loosely typed Value or null To declare a variable var variablename Beware of reserved words: E.g., if, Document, Math, etc.

JavaScript Operators Arithmetic Operators Operator Description Example Result + Addition x=2 4 y=2 x+y - Subtraction x=5 3 y=2 x-y * Multiplication x=5 20 y=4 x*y / Division 15/5 3 % Modulus (division remainder) 5/2 2,5 5%2 1 10%8 2 10%2 0 ++ Increment x=5 x=6 x++ -- Decrement x=5 x=4 x--

JavaScript Operators Assignment Operators Operator Example Is The Same As = x=y x=y += x+=y x=x+y -= x-=y x=x-y *= x*=y x=x*y /= x/=y x=x/y %= x%=y x=x%y

JavaScript Operators Comparison Operators Operator Description Example == is equal to 5==8 returns false === is equal to (checks for both value and type) x=5 y="5" x==y returns true x===y returns false!= is not equal 5!=8 returns true > is greater than 5>8 returns false < is less than 5<8 returns true >= is greater than or equal to 5>=8 returns false <= is less than or equal to 5<=8 returns true

JavaScript Operators Logical Operators Operator Description Example && and x=6 y=3 or x=6 (x < 10 && y > 1) returns true y=3! not x=6 (x==5 y==5) returns false y=3!(x==y) returns true

User and Browser Events

Functions <script type= text/javascript > function dontclick() { alert("i told you not to click!"); } </script>... <input type="button" value="don't Click Me!" onclick="dontclick()"/>

Dialogs alert("hello!"); confirm("delete files?"); var name=prompt("your name?", "Tim Berners-Lee");

Coding Tips Check your statements are on one line Check your " and ' quotes match Take care with capitalisation Lay it out neatly - use tabs Use the Chrome developer tools Or Firebug for Firefox

A Word About Comments JavaScript Comments These comments must be within a script // begins a single line comment These can start anywhere on the line, but the remainder of the line becomes a comment /* All of your comments here */ Everything between the start and end comment markers are comments Can be on a single line or span many HTML Comments <!-- All of your comments here -->

Ending Statements With a Semicolon? With traditional programming languages, like C++ and Java, each code statement has to end with a semicolon (;). Many programmers continue this habit when writing JavaScript, but in general, semicolons are optional! Semicolons are required if you want to put more than one statement on a single line.

Example

JavaScript Libraries Prototype script.aculo.us Yahoo! User Interface Library Dojo jquery MooTools www.prototypejs.org/ script.aculo.us/ developer.yahoo.com/yui/ dojotoolkit.org/ jquery.com/ mootools.net/

Reminders for this week Do the JavaScript tutorials on w3schools: 'JS Basic : www.w3schools.com/js/ Assignment Reading: Pattern group I: Designing Effective Page Layouts Pages 631-657