Intro to JavaScript. Some simple examples Examples from our webpage Examples from Andrews webpage Today’s Example.

Slides:



Advertisements
Similar presentations
The Web Warrior Guide to Web Design Technologies
Advertisements

Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Lecture 1 Term 2 9/1/12 1. Objects You normally use the “.” Operator to access the value of an object’s properties. The value on the left of the “.” should.
JavaScript Describe common uses of JavaScript in Web pages.
Information Technology Center Hany Abdelwahab Computer Specialist.
Computer Science 103 Chapter 4 Advanced JavaScript.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
آموزش طراحی وب سایت جلسه دهم – جاوا اسکریپت 1 تدریس طراحی وب برای اطلاعات بیشتر تماس بگیرید تاو شماره تماس: پست الکترونیک :
Javascript and the Web Whys and Hows of Javascript.
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.
Generations of Programming Languages First generation  Machine Language Second Generation  Assembly Language Third Generation  Procedural language such.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
JavaScript Part 1.
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.
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.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
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.
1 JavaScript 2 JavaScript. 2 Rollovers Most web page developers first use JavaScript for rollovers A rollover is a change in the appearance of an element.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
JavaScript Making Web pages come alive. Objectives Be able to read JavaScript scripts Be able to write JavaScript scripts.
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.
COMP403 Web Design JAVA SCRİPTS Tolgay KARANFİLLER.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Jaana Holvikivi 1 Introduction to Javascript Jaana Holvikivi Metropolia.
IS2802 Introduction to Multimedia Applications for Business Lecture 3: JavaScript and Functions Rob Gleasure
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
HTML Overview Part 5 – JavaScript 1. Scripts 2  Scripts are used to add dynamic content to a web page.  Scripts consist of a list of commands that execute.
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.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Java Script About Java Script Document Object Model Incorporating JavaScript Adding JavaScript to HTML Embedding a Javascript External Scripts Javascript.
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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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 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.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
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.
Copyright © Terry Felke-Morris Web Development & Design Foundations with HTML5 8 th Edition CHAPTER 14 KEY CONCEPTS 1 Copyright.
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
JavaScript is a programming language designed for Web pages.
Donna J. Kain, Clarkson University
Barb Ericson Georgia Institute of Technology May 2006
Introduction to Scripting
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
JavaScript Basics What is JavaScript?
JavaScript is a scripting language designed for Web pages by Netscape.
JavaScript: Introduction to Scripting
Web Programming and Design
Presentation transcript:

Intro to JavaScript

Some simple examples Examples from our webpage Examples from Andrews webpage Today’s Example

event example the code: Don't click here onclick is an event. – It is the event that occurs when the user clicks the link. alert is a function. – It takes a single argument which is a string.

Events Events are triggered by user actions or the browser itself. Common User actions: –Common events include: onMouseOver, onMouseOut, onClick These 3 events are mostly commonly used with anchor tags –Others include onFocus, onBlur Document events: –onLoad and onUnLoad are examples of events not triggered by the user.

Alert alert is used to grab the attention of the user –Syntax: alert(string); Ex: alert(“You have not entered a valid name.”) Ex. alert(“Hello “ + name + “!”); The look of the alert box is defined by the browser and platform. Gets the users attention but abusing it can easily be abused

Variables Declare Variables with var –var i; –Not necessary but a good practice. Assign variables with = –var i = 7; –var name = “Eric”; JavaScript is a non-typed language

Variable assignment Valid x = 7; y = x; x = y + 10; y = y + 4; var first = “jon”; var last = “doe”; var name = fist + “ “ + last; Not Valid 7 = x;

Object example The code: our webpage. Watch the status bar window is an object. status is a property of window –Setting the status bar sets the message at the bottom of the browser.

Objects Javascript is an object oriented language. –Though because it is so ‘loose’ with its typing many don’t think of it as one. Objects are variables with properties and fields –These properties may be other variables or functions The “.” operator is used to access the methods and properties of an object. –Eg: eric.age = 24;

new Objects are declared using new. –var eric = new Object() Properties are not declared with var. You just assign them. –eric.name = “Eric Traub”; eric.age = “24”; Will talk about how to assign methods to an object next week.

Script example The code: <!-- var now = new Date(); var hour = now.getHours(); if (hour > 5 && hour <= 11) { document.write(" Good Morning! "); } else if (hour > 11 && hour <= 17) { document.write(" Good Afternoon! "); } else { document.write(" Good Evening! "); } // -->

Script Example part 2 is the tag used to indicate that you are writing javascript and not html. if and else are used to make conditional statements. document.write tells javascript to insert html into the page

The tag The main property of is language. –Eg. –If you don’t specify a language the default is javascript. –You can also specify a version number Always close the tag, or your code will not work. Enclose your javascript code within a html comment block, to make the page comaptible with non-javascript browsers.

document.write document.write will write it’s argument as plain html onto the page. –Eg: document.write(“Hello there “ + name);

if statement if is used to execute code only is some condition is true if (age >= 18) { adult = true; } else used with if to execute a second statement if the condition is false if (sex == “male”) { title = “Mr”; } else { title = “Ms”; }

else if else if used for linking several if statement together. if (phd == true) { title = “Dr.”; } else if (sex == “male”) { title = “Mr.”; } else if (sex == “female”) { title = “Ms.”; } else { title = “????”; /* Not male or female! */ }

Comparison There are several operators used for making comparisons between variables The main arithmetic comparitors are:  == equal  < less than  < less than or equal to  > greater than  >= greater than or equal to  != not equal to

Logic When making comparison you can also use logic functions –&& for and – || for or (that’s two ‘pipes”; shift backslash) –! For not Eg: if (age > 18 && age < 65) { price = “$10”; } else { price = “$6”; }

More logic example if (customer.age <= 18 && movie.rating == “R” && !(customer.parentPresent())) { document.write(“No admittance”); }

Coding tips Use the debug window in Netscape –Type “javacript:” in the location bar. Check your work in IE and Nestscape Watch out for the cache –Use Control-Refresh in IE –Use shift-Reload in Netscape