W. W. Milner JavaScript. W. W. Milner Chapter 1 - Intro Why use JavaScript? Interactivity LiveScript JavaScript Jscript ECMAScript JavaScript is not Java!

Slides:



Advertisements
Similar presentations
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Advertisements

 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
The Web Warrior Guide to Web Design Technologies
JavaScript- Introduction. What it is and what it does? What it is? It is NOT Java It is NOT Server-side programming Users can see code It is a client-side.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Tutorial 10 Programming with JavaScript
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
JavaScript Programming Basics Chapter What is Programming?
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
Forms and Java script. Forms The graphical user interface -textbox, radio, button, textarea, checkbox… The processing script –CGI scripts, Perl script,
Scripting Languages.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
UNIT 3 DYNAMIC WEBSITES WITH CSS AND JAVASCRIPT. OBJECTIVES  CO4 Apply style to a website using CSS.  CO5 Describe the use of scripting when creating.
Programming with JavaScript (Chapter 10). XP Various things Midterm grades: Friday Winter Career Fair – Thursday, April 28, 2011 (11 am to 3 pm). – MAC.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Advanced Web Design Scripting Tutorial Chapters. Scripting Intro The scripting part of the forthcoming Advanced Web Design textbook introduces you to.
The Bean Counter: A JavaScript Program
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
JavaScript Part 1.
JavaScript 1. What is JavaScript? JavaScript allows web authors to create dynamic pages that react to user interaction. It is an Object-based because.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
1 Introduction to Javascript Peter Atkinson. 2 Objectives To understand and use appropriately some of the basic elements of Javascript: –alert and prompt.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1 JavaScript in Context. Server-Side Programming.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 14 JavaScript.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Topic: An Introduction to JavaScript - from Beginning JavaScript by Wilton (WROX)
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
 2001 Deitel & Associates, Inc. All rights reserved. 1 Chapter 20 – Dynamic HTML: Object Model and Collections Outline 20.1Introduction 20.2Object Referencing.
Introduction to Javascript. What HTML Can & Can Not Do HTML Can HTML Can Display text Display text Display images Display images Display even animated.
JavaScript - A Web Script Language Fred Durao
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
1 JavaScript
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
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.
Jaana Holvikivi 1 Introduction to Javascript Jaana Holvikivi Metropolia.
1 JavaScript in Context. Server-Side Programming.
Making dynamic pages with javascript Lecture 1. Java script java versus javascript Javascript is a scripting language that will allow you to add real.
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.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Tutorial 11 1 JavaScript Operators and Expressions.
Scripting with Client-Side Processing Scripting with Client Side Processing Lesson – Web Technologies Copyright © Texas Education Agency, All rights.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
The Magic of Dynamic Web Pages Doncho Minkov Telerik Software Academy academy.telerik.com Technical Trainer
The Magic of Dynamic Web Pages Telerik Software Academy JavaScript Fundamentals.
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Changing CSS Styles via JavaScript No readings?. 2 Review? You can change the CSS styling of an element with JavaScript Syntax is similar to accessing.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
Web Development & Design Foundations with HTML5
Web Development & Design Foundations with HTML5 7th Edition
Introduction to JavaScript Development
Web Programming and Design
Web Programming and Design
Presentation transcript:

W. W. Milner JavaScript

W. W. Milner Chapter 1 - Intro Why use JavaScript? Interactivity LiveScript JavaScript Jscript ECMAScript JavaScript is not Java! Programming…..

W. W. Milner Chapter 2 Do what it says on page 5

W. W. Milner The first script <!-- alert("Hello world"); //-->

W. W. Milner Using separate script files HelloWorld Some page content

W. W. Milner Chapter 3 Variables – data values held in memory Declaring variables var price=2.50;

W. W. Milner Input Entering data values at ‘run-time’ price = prompt("Enter the price", "10.00");

W. W. Milner What’s wrong? price = prompt "Enter the price", "10.00"; price = prompt("Enter the price", "10.00"; price = prompt("Enter the price", 10.00); price = prompt( Enter the price", "10.00"); prompt("Enter the price", "10.00"); price = prompt("Enter the price", "10.00")

W. W. Milner Arithmetic total = price * quantity; result = 2 + 3; result = * 4; result = (1 + 3) * 4; result = 7 / 8; Try page 12

W. W. Milner Data type Number, date, currency, boolean… String type = string of characters Enclose in quotes – var myName; myName = “Walter Milner”;

W. W. Milner String concatenation A + joins strings string1 = “fat “; string2 = “cats”; alert(string1+string2); >> fat cats What is "9" + "9"?

W. W. Milner Changing string type to number answer = "123.4"; result = parseFloat(answer);

W. W. Milner if - the decision statement unitPrice = 1.30; if (quantity > 100) unitPrice = 1.20; SymbolMeaning >greater than <less than >=greater than or equal to <=less than or equal to ==equal !=not equal Do task on page 14

W. W. Milner Repeating - loops var counter; for (counter=0; counter<4; counter++ ) alert(counter); Do task on page 15

W. W. Milner Chapter 3 - functions Code structure - splitting code into parts Function like mini-program Data comes in, processed, result returned

W. W. Milner Example function function average(a,b,c) { var total; total = a+b+c; return total/3; } Values come in here Value returned here

W. W. Milner Call and return of function function average(a,b,c) { var total; total = a+b+c; return total/3; }.. x=4; y=3; z=2; answer=average(x,y,z); alert(answer); start function call x y z copied to a b c

W. W. Milner functions do the tasks page 17/18

W. W. Milner event-handling functions examples of events - key press, mouse move, mouse click, timer times out GUI programming = responding to user events event-handler = function called when an event happens

W. W. Milner functions <!-- function greet() { alert("Loaded"); } //--> The onLoad event do task page 18/19

W. W. Milner Chapter 5 - The DOM A way to refer to things in the window objects properties methods events

W. W. Milner DOM example var newWindow =window.open("","nw", "menubar, status, resizable"); newWindow.status ="Hello folks"; newWindow.resizeTo(400,200); Do task top of page 21

W. W. Milner DOM hierarchy window navigatorscreendocumenthistorylocation form buttonform

W. W. Milner navigator alert(window.navigator.userAgent); the window the navigator in the window the useragent property of the navigator

W. W. Milner screen readonly window.moveTo(0,0); x = screen.availWidth; y = screen.availHeight; window.resizeTo(x,y );

W. W. Milner location location.href="

W. W. Milner document document.bgColor="yellow"; document.write("This is some bold text "); Try the tasks on page 23

W. W. Milner Forms CGI GET and POST and server-side processing JavaScript client-side processing Form data validation

W. W. Milner Form example Result:

W. W. Milner Event-handler for button function doAdd() { var number1, number2, result; number1=parseFloat(myform.num1.value); number2=parseFloat(myform.num2.value); result = number1+number2; myform.result.value=result; }

W. W. Milner Forms task Try the task on page 27

W. W. Milner Form data validation function checkForm() { var OK=true; if (document.form1.forename.value=="") { alert("Please type in your forename"); document.getElementById("fNamePrompt").style.color="red"; OK=false; } if (document.form1.surname.value=="") { alert("Please type in your surname"); document.getElementById("sNamePrompt").style.color="red"; OK=false; } if (OK) { // submit form here }

W. W. Milner Form validation task Try the task on page 29

W. W. Milner Chapter 7 - The Math object function rollDice() { var x = Math.random(); x = 6*x; x = Math.floor(x); x=x+1; alert(x); } Task on page 31

W. W. Milner Date object var now = new Date(); var result="It is now "+now; document.getElementById("timeField").innerText=result;.. hours = now.getHours(); Task on page 32

W. W. Milner Timing - setTimeout interval = setTimeout('bang()', 5000); 5 seconds after this statement executes, this function is called make something happen (once) after a fixed delay clearInterval(interval); cancels this

W. W. Milner setInterval makes something happen repeatedly at fixed intervals interval = setInterval('ticktock()', 1000); this function is called every second after this clearInterval(interval); stops it

W. W. Milner Timing - tasks Try page 33

W. W. Milner Chapter 8 - Standard tricks - rollovers.. function showPic(f) { document.pic.src=f; } // --> Pic one Pic two

W. W. Milner Image roll-over <!-- function showPic(f) { document.pic.src=f; } // --> Task - try this out - produce a page showing an image, which changes to a second image when the mouse goes over it, and a third image when the mouse leaves it. Get images from the Web or draw them using the graphics software on the computer

W. W. Milner Pre-loading images <!-- var image1, image2, image3; function preLoad() { image1 = new Image(30,30); image2 = new Image(30,30); image3 = new Image(30,30); image1.src="default.gif"; image2.src="pic1.gif"; image3.src="pic2.gif"; document.pic.src = image1.src; } // --> <body onLoad="preLoad()" onMouseOver="document.pic.src = image2.src" >

W. W. Milner Menus

W. W. Milner Styles for menus <!-- #ID1, #ID2 { /* initial settings of the two menu blocks */ font-family: Geneva, Arial, Helvetica, san-serif; font-size: 12px; color: #FFFFFF ; display : none; /* <<<< so you cant see them */ background-color= #ffff00; position: absolute; top: 40px; width: 55px; border: thin solid black }.. -->

W. W. Milner JavaScript for the menus function mouseMethod(leftPos, whichID) { /* when they click on a menu item */ /* change from display none to display block - can see it */ document.getElementById(whichID).style.display = "block"; /* make it correct position across screen */ document.getElementById(whichID).style.left = leftPos; } function hideAgain(whichID) { /* when they click hide, revert to display none */ document.getElementById(whichID).style.display = "none"; } Task - Try this out. Add a third block