Introduction to Javascript. What HTML Can & Can Not Do HTML Can HTML Can Display text Display text Display images Display images Display even animated.

Slides:



Advertisements
Similar presentations
Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
JavaScript (Part 2) CS 183 4/13/2010. JavaScript (Part 2) Will cover: ◦ For.. In ◦ Events ◦ Try.. Catch, Throw ◦ Objects.
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.
Information Technology Center Hany Abdelwahab Computer Specialist.
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.
Introduction to Javascript. Web Page Technologies To create Web Page documents, you use: To create Web Page documents, you use: HTML – contents and structures.
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Introduction to scripting
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
Javascript and the Web Whys and Hows of Javascript.
Introduction to JavaScript Dr. John P. Abraham University of Texas – Pan American.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
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.
Intro to JavaScript. Use the tag to tell the browser you are writing JavaScript.
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 Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
JAVASCRIPT QUIZ BOWL By: Joseph Lindo. Quiz Bowl Mechanics  Group w/ 5 maximum members  Question is presented at the board  Prepare piece of papers.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
JavaScript - A Web Script Language Fred Durao
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
Intro to JavaScript. Some simple examples Examples from our webpage Examples from Andrews webpage Today’s Example.
1 JavaScript
1 A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 4 JavaScript and.
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.
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES.
Introduction to JavaScript Objects, Properties, Methods.
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.
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
Jaana Holvikivi 1 Introduction to Javascript Jaana Holvikivi Metropolia.
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.
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.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
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.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
JavaScript: A short introduction Joseph Lee Created by Joseph Lee.
Copyright © Terry Felke-Morris Web Development & Design Foundations with HTML5 8 th Edition CHAPTER 14 KEY CONCEPTS 1 Copyright.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
Third lecture Event 27/2/2016 JavaScript Tutorial.
CGS 3066: Web Programming and Design Spring 2017
Chapter 6 JavaScript: Introduction to Scripting
Web Development & Design Foundations with HTML5
JavaScript is a programming language designed for Web pages.
Introduction to Javascript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Web Development & Design Foundations with HTML5 7th Edition
JavaScript.
14 A Brief Look at JavaScript and jQuery.
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
Introduction to JavaScript
Web Design and Development
JavaScript Basics What is JavaScript?
Presentation transcript:

Introduction to Javascript

What HTML Can & Can Not Do HTML Can HTML Can Display text Display text Display images Display images Display even animated clipart Display even animated clipart Allow users to input data Allow users to input data HTML Can Not HTML Can Not Do calculations Do calculations Display current date Display current date Check validity of input data Check validity of input data Change color of a button when the cursor hovers over it Change color of a button when the cursor hovers over it Be interactive Be interactive

Programming For a Web Page to be able to be interactive For a Web Page to be able to be interactive Calculate Calculate Display current date Display current date Check validity of input data Check validity of input data Change color of a button when the cursor hovers over it Change color of a button when the cursor hovers over it Add dynamic effects Add dynamic effects You need to include a program You need to include a program A set of detailed instruction to the computer to accomplish some task. A set of detailed instruction to the computer to accomplish some task. Using a programming language Using a programming language JavaScript JavaScript Java Java Visual Basic Visual Basic

What Is Javascript? A scripting language used to add greater power and interactivity to Web pages A scripting language used to add greater power and interactivity to Web pages Freely combined with HTML in the Web document Freely combined with HTML in the Web document Invented by Netscape, now controlled by a European Standards group Invented by Netscape, now controlled by a European Standards group Often called a scripting language, rather than a programming language Often called a scripting language, rather than a programming language Distinct from Java, which is a full-fledged programming language invented by Sun Microsystems. Distinct from Java, which is a full-fledged programming language invented by Sun Microsystems.

Screen Output var message = alert(“Aloha, you’all.”); var message = alert(“Aloha, you’all.”); var question = confirm(“Do you want to continue?”); var question = confirm(“Do you want to continue?”); document.write (“Welcome to Hawaii.”); document.write (“Welcome to Hawaii.”);

Keyboard Input var name = prompt(“What is your name?”); alert(“Welcome to Hawaii, “ + name); var name = prompt(“What is your name?”); alert(“Welcome to Hawaii, “ + name);

Embedding JS Code in HTML Page <html><head> Java Script Demo Java Script Demo </head><body> Javascript Demo Javascript Demo var mess = alert("Aloha, you'all."); var mess = alert("Aloha, you'all."); var quest = confirm("Do you want to continue?"); var quest = confirm("Do you want to continue?"); var name = prompt("What is your name?", ""); var name = prompt("What is your name?", ""); document.write("How are you, " + name + "?"); document.write("How are you, " + name + "?");</script></body></html>

Sample Web Page with Javascript Alert Demo (JS code) Alert Demo (JS code) Alert JS code Alert JS code Prompt Demo (JS code) Prompt Demo (JS code) Prompt JS code Prompt JS code Date Demo (JS code) Date Demo (JS code) Date JS code Date JS code

Other Examples of JS Use Create a New Window On the Fly Create a New Window On the Fly Create a New Window On the Fly Create a New Window On the Fly Check the Validity of Form Entries Check the Validity of Form Entries Check the Validity of Form Entries Check the Validity of Form Entries Manipulate Document Objects Manipulate Document Objects Manipulate Document Objects Manipulate Document Objects

Calling Functions Greet on Click (Code) Greet on Click (Code) Greet on Click Code Greet on Click Code Change Background on MouseOver (Code) Change Background on MouseOver (Code) Change Background on MouseOver Code Change Background on MouseOver Code Alert on Click (Code) Alert on Click (Code) Alert on Click Code Alert on Click Code

JS Demo function greet() { alert("Hello"); } Javascript ONCLICK Demo Greet on Click

JS Demo function toBlue() { document.bgColor="0000ff| } function toWhite() { document.bgColor="ffffff"; }... Change Background on MouseOver

... Javascript ONMOUSEOVER Demo </html

JS Demo function quote(mesg){ alert(mesg); } Famous Quotes Alert on Click

... </html

JS Demo Javascript Demo Where to Embed JS Function (1)

JS Demo function greet() { alert("Hello"); } Javascript ONCLICK Demo Where to Embed JS Function (2)

Javascript Language Basics

General Rules JS is case sensitive. JS is case sensitive. Sum = n1 + n2; // These statements are different sum = N1 + N2; Sum = n1 + n2; // These statements are different sum = N1 + N2; All JS variables are of variant type (not specific) All JS variables are of variant type (not specific) Variables may be declared, or not Variables may be declared, or not var num1 = 5 var str1 = “hello” num2 = 6 str2 = “Goodbye” var num1 = 5 var str1 = “hello” num2 = 6 str2 = “Goodbye” Comments Comments // This form is for short comments to end of line // This form is for short comments to end of line /* This form of delimiters can span several lines of comments. */ /* This form of delimiters can span several lines of comments. */

Variables firstName = "Maria"; // String value lastName = "Martinez"; // " myMotto = "Be Prepared"; // " myAge = 21; // integer value priceOfBook = 27.25; // float value priceOfCD = 18.50; // "

Operators // concatenation operator fulName = firstName + " " + lastName; // arithmetic operator totalPrice = priceOfBook + priceOfCD; // arithmetic operator ageOfMyBrother = myAge - 2;

Pre-defined Functions // current date and time today = new Date(); // year value (integer) of today year = today.getYear(); // pop up a window displaying alert("Welcome to Honolulu"); // prints string to the current page document.write("Hello."). document.writeln(" Good-bye");

User-defined Functions function greet() { alert("Welcome to Hawaii."); } function greetWithName(name) { alert("Welcome to Hawaii, " + name); } function changeBackColor(someColor) { alert("Here is a new background color."); document.bgColor = someColor; }

Events Event is an action external to the program that triggers a code to be executed. Event is an action external to the program that triggers a code to be executed. Partial List of Events Partial List of Events Event Works with When Onclick A, INPUT (e.g., button), FORM, TABLE, & many others an element is clicked

Event Works with When onblur A, AREA, BUTTON, INPUT, LABEL, SELECT, TEXTAREA the mouse leaves an element which was in focus onload BODY, FRAMESET a page is loaded into the browser ondblclick Same as ONCLICK an element is double-clicked onmouseover Same as ONCLICK mouse is moved over the element onmouseout Same as ONCLICK mouse is moved out of the element's area

Open/Close New Window To Open a new window: To Open a new window: myWindow = window.open( “nameOfMyWindow”); myWindow = window.open( “nameOfMyWindow”); To Close a window: To Close a window: nameOfMyWindow.close(); or (for active window) nameOfMyWindow.close(); or (for active window) window.close(); window.close();

Customizing Window OptionExplanation toolbar = yes | noAdd /remove browser toolbar location = yes | noAdd/ remove browser location field directories = yes | noAdd/ remove browser directories field status = yes | noAdd/ remove browser status field menubar = yes | noAdd/ remove browser menubar scrollbar = yes | noAdd/remove browser scrollbar resizable = yes | noAllow new window to be resizable width = valueSet window width in pixels height = valueSet window height in pixels

New Window--Example pageURL= windowName=“myPopupWindow”; pageURL= windowName=“myPopupWindow”; settings= "toolbar=yes,location=yes,directories=yes,"+ "status=no,menubar=no,scrollbars=yes,"+ "resizable=yes,width=600,height=300"; myNewWindow= window.open(pageURL, windowName, settings); (Note: no space between settings)

New Window--Example Click Here To Go to Yahoo