Web Usability Using JavaScript An Introduction to JavaScript Universidade Federal do Rio de Janeiro Departamento de Eletrônica e Computação Programação.

Slides:



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

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Javascript Introduction Norman White Material is from w3schools.com Go there to run examples interactively.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
The Web Warrior Guide to Web Design Technologies
Computer Science 103 Chapter 4 Advanced JavaScript.
JavaScript Client Side scripting. Client-side Scripts Client-side scripts, which run on the user’s workstation can be used to: Validate user inputs entered.
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
JavaScript Teppo Räisänen LIIKE/OAMK HTML, CSS, JavaScript HTML defines the structure CSS defines the layout JavaScript is used for scripting It.
Introduction to JavaScript. JavaScript Facts A scripting language - not compiled but interpreted line by line at run-time. Platform independent. It is.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JavaScript Part 1.
JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client.
DOM and JavaScript Aryo Pinandito.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
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.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Tutorial 10 Programming with JavaScript
Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
Using Client-Side Scripts to Enhance Web Applications 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
JavaScript - A Web Script Language Fred Durao
JavaScript Syntax, how to use it in a HTML document
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
05 – Java Script (1) Informatics Department Parahyangan Catholic University.
By Tharith Sriv. To write a web page you use: HHTML (HyperText Markup Language), AASP (Active Server Page), PPHP (HyperText Preprocessor), JJavaScript,
COMP403 Web Design JAVA SCRİPTS Tolgay KARANFİLLER.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
COS 125 DAY 20. Agenda Assignment 8 not corrected yet Assignment 9 posted  Due April 16 New course time line Discussion on Scripts 
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Pertemuan 5 IT133 Pengembangan Web JavaScript. What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
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.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
COM621: Advanced Interactive Web Development Lecture 5 – JavaScript.
Introduction to.
Tutorial 10 Programming with JavaScript
Week 4: Introduction to Javascript
Web Development & Design Foundations with HTML5 7th Edition
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
14 A Brief Look at JavaScript and jQuery.
JavaScript Introduction
JavaScript an introduction.
Web Systems Development (CSC-215)
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
Functions, Regular expressions and Events
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
Web Programming and Design
Week 5: Recap and Portfolio Site
Web Programming and Design
Web Programming and Design
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

Web Usability Using JavaScript An Introduction to JavaScript Universidade Federal do Rio de Janeiro Departamento de Eletrônica e Computação Programação Avançada Alberto Wagner Collavizza Based on Mel Anderson’s JavaScript Presentation

What is JavaScript? A lightweight programming language that runs in a Web browser (client-side) Embedded in HTML files and can manipulate the HTML itself Interpreted, not compiled JavaScript is not Java Developed by Netscape, not Sun Only executed in a browser Is not a full-featured programming language However, the syntax is similar

Why use JavaScript? To add dynamic function to your HTML JavaScript does things that HTML can’t, like logic You can change HTML on the fly To shoulder some of the form-processing burden JavaScript runs in the browser, not on the Web server Better performance JavaScript can validate the data that users enter into the form, before it is sent to your Web application.

When not use JavaScript? When you need to access other resources Files Programs Databases (Unless using AJAX and a Web service) When you are using sensitive or copyrighted data or algorithms Your JavaScript code is open to the public.

Add JavaScript to HTML In the HTML page itself: // JavaScript code As a file, linked from the HTML page:

Functions JavaScript instructions are usually grouped together in a function: function myFunction(a, b, c, d) { //There is no need to define types (parameters and return) return a + “ ” + b + “ ” + c + “ ” + d; } Like a method, procedure, or subroutine Functions are called using parenthesis, like C The name of a function without parenthesis is a reference to it, and can be used as a parameter

Events There are two ways to execute a JavaScript code As the browser loads the page, inside tags Using HTML events, something has to happen before the JavaScript is executed JavaScript defines various events: onClick – link or image is clicked onSubmit – a form is submitted onMouseOver – the mouse cursor moves over it onChange – a form control is changed onLoad – something gets loaded in the browser etc Events are specified in the HTML code.

Event Example function myFunction() { // code }

Variables, Arrays and Hashes JavaScript has untyped variables Variables are declared with the var keyword: var num = “1”; var name = “Mel”; var phone = “ ”; Arrays are created using square brackets: var myColors = [“red”, “blue”, “yellow”, “green”]; Hashes (Objects) are created using curly brackets: var myUser = { name: “Alberto”, age: 22 };

More about Objects Every object in JavaScript is treated as an associative array The codes below are all equivalent var myUser = { name: “Alberto”, age: 22 }; var myUser = new Object(); myUser.name = “Alberto”; myUser.age = 22; var myUser = new Object(); myUser[“name”] = “Alberto”; myUser[“age”] = 22;

Functions Reference function alertOne() { alert(“I’m a global function!”); } function runFunction(funct) { if (typeof funct == “function”) { funct(); } } var obj = { letMeAlertSomething: function() { alert(“I’m an object function!”); }; } obj.letMeAlertSomething(); //Calling function runFunction(obj.letMeAlertSomething); //Passing function as parameter (function() { alert(“I’m an anonymous function!”) })();

Null and Undefined In JavaScript, undefined means a variable has been declared but has not yet been assigned a value, such as var testVar; alert(testVar); //shows undefined alert(typeof testVar); //shows undefined Null is an assignment value. It can be assigned to a variable as a representation of no value: var testVar = null; alert(testVar); //shows null alert(typeof testVar); //shows object

The DOM Unlike other programming languages, JavaScript understands HTML and can directly access it JavaScript uses the HTML Document Object Model to manipulate HTML The DOM is a hierarchy of HTML things Use the DOM navigate across HMTL elements

DOM Example […] I’m a Title Do you know Google? Google And what about jQuery? jQuery […] var p = document.getElementById(“content”); for (var i = 0; I < p.childNodes; i++) alert(p.childNodes[i].tagName); // h2, a, h2, a alert(p.parentNode.tagName); //div var div = document.createElement(“div”); div.innerHTML = “Oi!”; p.appendChild(div”);

Debugging JavaScript Firebug Firefox Plug-in Edit, debug and monitor CSS, HTML, and JavaScript Incredible JavaScript Profiler

Useful Links Tutorials JavaScript Libraries EXT JS - jQuery -

Questions?