22.12.2015Jaana Holvikivi 1 Introduction to Javascript Jaana Holvikivi Metropolia.

Slides:



Advertisements
Similar presentations
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
Advertisements

The Web Warrior Guide to Web Design Technologies
Georgia Institute of Technology JavaScript part 2 Barb Ericson Georgia Institute of Technology May 2006.
Multimedia and the World Wide Web HCI 201 Lecture Notes #8B.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
20-Jun-15 JavaScript and HTML Simple Event Handling.
Information Technology Center Hany Abdelwahab Computer Specialist.
Lesson 2 Event Handling. Object Event Handlers Most of the objects that make up the Document Object Model respond to asynchronous, user generated events.
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 What JavaScript Is: a general purpose scripting language that allows a static page to interact with users and respond to events.
UNIT 6 JAVASCRIPT EVENT HANDLERS &WEB BROWSERS DETECTION.
CP476 Internet Computing JavaScript and HTML1 1.JavaScript Execution Environment The JavaScript Window object represents the window in which the browser.
HTML Forms/Events (Instructor Lesson) The Event model HTML Forms Custom Events 1.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
Chapter 19: Adding JavaScript
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
Chapter 5 © 2003 by Addison-Wesley, Inc. 1 Chapter 5 JavaScript and HTML Documents.
JavaScript II ECT 270 Robin Burke. Outline JavaScript review Processing Syntax Events and event handling Form validation.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JavaScript Part 1.
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.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
1 Introduction to Javascript Peter Atkinson. 2 Objectives To understand and use appropriately some of the basic elements of Javascript: –alert and prompt.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
Intro to JavaScript Scripting language –ECMAScript compliant –Client side vs. server side Syntactic rules –White space –Statement end: ; optional –Comments:
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
Event JavaScript's interaction with HTML is handled through events that occur when the user or browser manipulates a page. When the page loads, that is.
Introduction To JavaScript. Putting it Together (page 11) All javascript must go in-between the script tags. All javascript must go in-between the script.
JavaScript. JavaScript is a programming language used to make web pages interactive. JavaScript is scripting language used for client side scripting.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Making dynamic pages with javascript Lecture 1. Java script java versus javascript Javascript is a scripting language that will allow you to add real.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
Project 8: Reacting to Events Essentials for Design JavaScript Level One Michael Brooks.
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.
Web Programming Java Script & jQuery Web Programming.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
H.Melikyan/4910/031 Programming the World Wide Web JavaScript Dr.Hayk Melikyan Departmen of Mathematics and CS JavaScript and HTML Documents.
JavaScript II ECT 270 Robin Burke. Outline Functions Events and event handling Form validation.
JavaScript Event Handlers. Introduction An event handler executes a segment of a code based on certain events occurring within the application, such as.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
Scripting with Client-Side Processing Scripting with Client Side Processing Lesson – Web Technologies Copyright © Texas Education Agency, All rights.
This is our seminar JavaScript And DOM This is our seminar JavaScript And DOM.
Chapter 5: Intro to Scripting CIS 275—Web Application Development for Business I.
Chapter 4 Java Script - Part1. 2 Outlines Introduction to Java Script Variables, Operators and Functions Conditional statements JavaScript Objects Forms.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
Methods and Object Information. Some Document Methods.
5.1 JavaScript Execution Environment
JavaScript and HTML Simple Event Handling 11-May-18.
JavaScript.
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript and HTML Simple Event Handling 19-Sep-18.
CHAPTER 7 JavaScripts & HTML Documents
JavaScript and Ajax (JavaScript Events)
Web Programming and Design
Web Programming and Design
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

Jaana Holvikivi 1 Introduction to Javascript Jaana Holvikivi Metropolia

Jaana Holvikivi2 Javascript on HTML pages HTML STYLE HEAD BODY Javascript SCRIPT STYLEsheet Javascript file

Jaana Holvikivi3 Javascript on an HTML page Javascript basics document.write(”Updated:"); document.write(document.lastModified);

Jaana Holvikivi4 Javascript basics <a href=" onMouseOver="window.status=' click here '; return true" onMouseOut="window.status=' '; "> Click the link about Metropolia Javascript on an HTML page

Jaana Holvikivi5 Javascript on an html page Javascript and DOM var date=new Date(); var hour=date.getHours(); if (hour>=22 || hour<=5) document.write("You should go to sleep"); else document.write("Hello, world!");

Jaana Holvikivi6 External code file var date=new Date(); var hour=date.getHours(); if (hour>=22 || hour<=5) document.write("You should go to sleep"); else document.write("Hello, world!"); jsdom.js: Javascript and DOM I love you! Hello, world! I love you!

Jaana Holvikivi7 Programming language features  Data types  Constants  Variables  Expressions  Statements  Operators  Statements: conditional, loops  Functions  Methods  Events

Jaana Holvikivi8 Variables and values var i=0, result = 0; // = assingment statement for (i = 0; i "); } var i = 0declares a variable and sets the value to 0 (assignment statement) ;statement terminator Var a, A; JavaScript is case sensitive A declared variable is local Reserved words cannot be used as variable names

Jaana Holvikivi9 Data types in JavaScript  Numbers 0.44  Strings document.write (”greeting"+mj); in quotations ( ' or ")  Null”empty"  String literals alert("I am an alert box!! \n\t Man!"); when HTML is not in use, adds a new line and a tab  Boolean values true, false

Jaana Holvikivi10 Character strings  Methods to operate on strings; mj = "kissa"; other ="la" mj.lengthvalue 5 mj.toUpperCase()KISSA mj.charAt(0)k mj.substring(0,3)kiss concatenation: mj + otherkissala

Jaana Holvikivi11 Arrays blocks = [8, 4, 7, 6, 15] blocks.length gets value 5 blocks[0]contains number 8 novel = blocks.sort() Contains array [4,6,7,8,15] Arrays can contain different types of data document.images[0].src = pics [frame].src

Jaana Holvikivi12 Expressions i <= 10 conditional expression: true or false String operation: ”result is" + summa Statement: timerID = setTimeout(’alternate()', 800); ;statement terminator

Jaana Holvikivi13 Operators Assignment Operators +addition x+=y is the same as x=x+y x++same as x=x+1 - Subtraction * Multiplication /Division %remainder Comparison Operators, true or false ==is equal to !=is not equal5!=8 returns true <less than >Greater than >= Greater than or equal <=less than or equal

Jaana Holvikivi14 Operators Logical Operators &&AND ||OR !NOT RESULT AND OR NOT

Jaana Holvikivi15 Conditional statements  if ( !Math.random ) // here you check a standard function { document.write(' -- weather called off due to rain -- '); } else if ( Math.floor((Math.random()*2)) == 0 ) { document.write (" It's just awful. "); } else { document.write (" How wonderful it is! "); }

Jaana Holvikivi16 Loops  for (i = 0; i <= 10; i++)  { result += i; document.write(i + ": " + result + " "); } document.write(" ");  Increment i=i+1 or i++

Jaana Holvikivi17 Loops  var x = 1; var result = 0; while ( x 10 result += x; x++; } alert ("The result is " + result + " and x is " + x );

Jaana Holvikivi18 Functions User defined Predefined alert prompt parsIntconverts variable into an integer parseFloatconverts variable into a number Math.sqrtsquare root Math.floorrounding to the lower integer Math.roundrounding

Jaana Holvikivi19 Functions: user defined function disp_alert() { alert("I am an alert box!!") }

Jaana Holvikivi20 Methods  close()  getElementById()  getElementsByName()  getElementsByTagName()  open()  document.write() Closes an output stream opened with the document.open() method, and displays the collected data Returns a reference to the first object with the specified id Returns a collection of objects with the specified name Returns a collection of objects with the specified tagname Opens a stream to collect the output from any document.write() method Writes HTML expressions or JavaScript code to a document

Jaana Holvikivi21 Event handlers onabort Loading of an image is interrupted onblur An element loses focus onchange The user changes the content of a field onclick Mouse clicks an object ondblclick Mouse double-clicks an object onerror An error occurs when loading a document or an image onfocus An element gets focus onkeypress A keyboard key is pressed or held down onload A page or an image is finished loading onmousedown A mouse button is pressed onmouseout The mouse is moved off an element onmouseover The mouse is moved over an element onreset The reset button is clicked onresize A window or frame is resized onselect Text is selected onsubmit The submit button is clicked onunload The user exits the page setTimeout(), clearTimeout()timer is activated

Jaana Holvikivi22 Event: onload() & getElementById function process() {var string; string=" " + " Black " + " Red " + " Blue " + " "; var myDiv=document.getElementById("Hook"); myDiv.innerHTML=string; } ESIMERKIKSI: stories and headings Hook has an innerHTML-property stories and headings Hook has an outerHTML-property stories and headings

Jaana Holvikivi23..onload() AJAX Foundations: javascript and DOM Hello! Here is a cool list of colors for you:

Jaana Holvikivi24 DOM Document Object Model  document.form1.text1.value  parent.location = word1 + word2 + ".html"

Jaana Holvikivi25 Javascript as a programming language  Object-oriented:  Instead of writing procedural programs, write class libraries to encapsulate behaviors  DOM is not a collection of dumb elements but a hierarchy of types  Styles are properties of objects  Complete OO code with error handling, instance methods, static methods and type hierarchies  Versatile use of functions  A large number of object-oriented libraries  Used to create User Interfaces