JS Basics 1 Lecture JavaScript - Basics. JS Basics 2 What is JavaScript JavaScript is a “simple”, interpreted, programming language with elementary object-

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 I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
 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 Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
1 HCI 201 JavaScript - Part 1. 2 Static web pages l Static pages: what we have worked with so far l HTML tags tell the browser what to do with the content.
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Tutorial 10 Programming with JavaScript
Introduction to Web Site Development Steven Emory Department of Computer Science California State University, Los Angeles Lecture 8: JavaScript I.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Javascript and the Web Whys and Hows of Javascript.
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
Introduction to JavaScript. JavaScript Facts A scripting language - not compiled but interpreted line by line at run-time. Platform independent. It is.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Scripting Languages.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Introduction to JavaScript 11 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 14.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
1 CLIENT-SIDE SCRIPTS. Objectives 2 Learn how to reference objects in HTML documents using the HTML DOM and dot syntax Learn how to create client-side.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
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)
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
1 JavaScript in Context. Server-Side Programming.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Using Client-Side Scripts to Enhance Web Applications 1.
 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,
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
Introduction to JavaScript CS101 Introduction to Computing.
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.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming control structures, events, objects.
1 JavaScript in Context. Server-Side Programming.
Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing a Line of Text in a Web Page 7.3 Another JavaScript.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
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:
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
JavaScript: A short introduction Joseph Lee Created by Joseph Lee.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
CGS 3066: Web Programming and Design Spring 2017
Module 1 Introduction to JavaScript
Chapter 6 JavaScript: Introduction to Scripting
Donna J. Kain, Clarkson University
Introduction to Scripting
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Web Systems Development (CSC-215)
WEB PROGRAMMING JavaScript.
T. Jumana Abu Shmais – AOU - Riyadh
Tutorial 10: Programming with javascript
JavaScript is a scripting language designed for Web pages by Netscape.
Introduction to Programming and JavaScript
Presentation transcript:

JS Basics 1 Lecture JavaScript - Basics

JS Basics 2 What is JavaScript JavaScript is a “simple”, interpreted, programming language with elementary object- oriented capabilities JavaScript has two distinct but overlapping systems –client-side JavaScript runs on Web browsers –server-side JavaScript runs on Web servers Syntactically JavaScript resembles C, C++, Java JavaScript was developed by Netscape (formerly called LiveScript)

JS Basics 3 JavaScript is Embedded in HTML //the Javascript here produces content for the BODY on loading Deferred Script //the Javascript here creates functions for later use

JS Basics 4 A Simple Example Simple Javascript First Example of JavaScript <!-- hide from old browsers by embedding in a comment document.write(“Last updated on “ + document.lastModified + “.”) // end script hiding -->

JS Basics 5 Example 1: Browser Output

JS Basics 6 JavaScript has Event Handlers Handling Events Example Handling Events in JavaScript <INPUT TYPE=”button” VALUE=”Click me” onClick=alert(“You clicked me”) >

JS Basics 7 Example 3

JS Basics 8 Javascript: Console In addition to ftp: etc. javascript: can also be used in any context where a URL is permitted Entering javascript: in the location field brings up an error message window

JS Basics 9 What JavaScript Programs Can Do Write programs to perform any computation; it is equivalent in power to a general purpose programming language Control Web page appearance and content (this is its intended use) Control the Web browser, open windows and frames Interact with document content Retrieve and manipulate all hyperlinks Interact with the user Read/write client state with cookies

JS Basics 10 JavaScript - The Basics JavaScript is case-sensitive sum, SUM and Sum are 3 different identifiers –HTML is NOT case-sensitive JavaScript ignores spaces, tabs, newlines Semicolon is optional –but multiple statements on a line require a semicolon i = 1; j = 2 C and C++ style comments are supported //comment to end of line /* this can be a multiple line comment */

JS Basics 11 JavaScript Literals Escape sequences are used to embed special characters in a string \bbackspace\ttab \fform feed\’single quote \nnewline\”double quote \rcarriage return\\backslash Example of escape characters in strings msg = ‘You\’re using an embedded single quote here.’ msg = “This is on the first line \n and this is on the second line.” msg = document.title + “\n” + document.links.length + “links present”

JS Basics 12 JavaScript Variables Variables should be declared, but not their type var i, sum; var zero = 0;//declaration and initialization var myName = “Ellis” The type of value a variable can hold during execution may change. Any variable outside a function is a global variable and can be referenced by any statement in the document Variables declared in a function are local to the function In a multi-frame or multi-window set up of the browser, scripts can access global variables from any other document currently loaded

JS Basics 13 JavaScript Data Types TypeExampleDescription String“a string”a series of characters inside quote marks Number123.45Any number not inside quote marks Booleantruea logical true and false Nullnullcompletely devoid of any value, not a number, not a string, different than 0 in C/C++ Objectall properties and methods belonging to the object Functiona function

JS Basics 14 Array and Objects Objects and arrays are really identical typeof(array) = typeof(object) = object typeof() returns a string which is the type of its argument (“number”, “string”, “boolean, “object”, “function”, “undefined”) Object elements are accessed using dot (.) An object/array on the left requires a field name on the right of dot document.lastModified frames[0].length The dot operator can be used with arrays arr[1] is identical to arr.1 but if i = 1, arr[1] is not equivalent to arr.i since property names are not evaluated

JS Basics 15 Example Using new Example using new function outputDate() { var d = new Date(); //creates today’s date and time document.write(d.toLocaleString()); } // converts a //date to a string The date and time are outputDate();

JS Basics 16 Date: Browser Output

JS Basics 17 Using alert(), confirm(), and prompt() Example of alert, confirm, prompt function alertUser() { alert("An alert box contains an exclamation mark");} function confirmUser() { var msg = "\n please confirm that you want\n" + "to test another button?"; if (confirm(msg)) document.write(" You selected OK "); else document.write(" You selected Cancel "); } function promptUser() { name1=prompt("What is your name?”, “ “); document.write(" welcome to this page " + name1 + " "); }

JS Basics 18 Using alert(), confirm(), and prompt() welcome to this page

JS Basics 19 Clicking on alert()

JS Basics 20 Clicking on confirm()

JS Basics 21 Clicking on prompt()