JavaScript Introduction

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
The Web Warrior Guide to Web Design Technologies
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript - 1
Javascript and the Web Whys and Hows of Javascript.
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
4.1 JavaScript Introduction
Lecture Note 3: ASP Syntax.  ASP Syntax  ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source"
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
What is Java Script? An extension to HTML. An extension to HTML. Allows authors to incorporate some functionality in their web pages. (without using CGI.
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 AND DOM Internet Engineering Spring 2012.
JavaScript Syntax, how to use it in a HTML document
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
HTML JAVASCRIPT. CONTENTS Javascript Example NOSCRIPT Tag Advantages Summary Exercise.
JavaScript Introduction. Slide 2 Lecture Overview JavaScript background The purpose of JavaScript A first JavaScript example Introduction to getElementById.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
JavaScript Overview Developer Essentials How to Code Language Constructs The DOM concept- API, (use W3C model) Objects –properties Methods Events Applications;
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Understanding JavaScript and Coding Essentials Lesson 8.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
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.
The Web Wizard’s Guide To DHTML and CSS Chapter 2 A Review of CSS2 and JavaScript.
Introduction to Web Site Development Department of Computer Science California State University, Los Angeles Lecture 9: JavaScript.
REEM ALMOTIRI Information Technology Department Majmaah University.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
XHTML Forms.
Introduction to.
DHTML.
Module 1 Introduction to JavaScript
Java Script Introduction. Java Script Introduction.
JavaScript is a programming language designed for Web pages.
W3C Web standards and Recommendations
Section 17.1 Section 17.2 Add an audio file using HTML
Web Development & Design Foundations with HTML5 7th Edition
Exploring JavaScript Ch 14
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Introduction to JavaScript
JavaScript an introduction.
DHTML Javascript Internet Technology.
A second look at JavaScript
DHTML Javascript Internet Technology.
Introduction to JavaScript
Tutorial 10 Programming with JavaScript
E-commerce Applications Development
Introduction to DHTML, the DOM, JS review
Introduction to JavaScript
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
JavaScript is a scripting language designed for Web pages by Netscape.
An Introduction to JavaScript
Introduction to Programming and JavaScript
CNIT 133 Interactive Web Pags – JavaScript and AJAX
Web Client Side Technologies Raneem Qaddoura
Web Programming and Design
Web Programming and Design
Introduction to Web programming
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

JavaScript Introduction

Lecture Overview JavaScript background The purpose of JavaScript A first JavaScript example

History Lesson JavaScript is NOT Java Started at Netscape in 1995 Microsoft released its own version 'JScript" in 1996 JavaScript is the default scripting language in .NET and the Web for that matter (VBScript has pretty much faded away)

What do we do with JavaScript? Adds sizzle to pages (Animation) Dynamic HTML Client side data entry validation Reduce the load on overburdened servers Process and manage cookies AJAX to load parts of Web pages jQuery layered on top of JavaScript to make common tasks easy

What is JavaScript? (1) It’s a programming language that resembles Java but is loosely typed and interpreted Implementations European Computer Manufacturers Association created ECMAScript to standardize different scripting versions See ECMA-262 I’ll try to conform There are others It’s a “C ish” language

What is JavaScript (2) Most of what we do is to access the object model supported by the underlying browser Remember an HTML document is hierarchical – Now we can write programs to navigate that hierarchy The W3C defines the Document Object Model (DOM)

Creating a First Script <script> tag appears in a <head> or <body> tag type argument denotes that it’s JavaScript type is no longer required in HTML 5 Example: <script> document.write(“hello”); </script>

Creating a First Script Script language (Optional) <html> <body> <script type=“text/javascript"> document.write(“hello") </script> </body> </html> script tag End script tag

Script Placement (1) A document may have multiple <script> blocks Scripts in a <head> block Create procedures here Before or after the <style> section is fine Scripts in a <body> block Code executes as the page is rendered Importing external script files This is the recommended place to put generic functions and to create reusable libraries

Script Placement (2) Scripts appearing in a <head> tag but outside a procedure execute first in the order they appear Code inside a procedure is not executed unless explicitly called Scripts appearing in a <body> tag execute as they are encountered The placement has an effect on page rendering

The document Object Recall that there exists a hierarchical in-memory representation of an HTML document This is maintained by the browser in the document object JavaScript can be used to write HTML output to the document document.write(“Message”);

A First Script

A First Event-Driven JavaScript Program Create JavaScript statements to display the current date via the getElementById() method and Date() function Create a JavaScript function (event handler) containing the above code Wire the event handler to the function that will execute the function immediately after the page finishes loading

Using getElementById() It’s a key to working with JavaScript It gets a reference to an element having a specific value for the ID property That’s why ID must be unique Like a variable, it’s a unique identifier Once we have a reference to an element, we can manipulate it

Using getElementById (Example) Get a reference to the element <span> whose ID property has a value of spnDate and display the current date as that tag’s content var spnDate; spnDate = document.getElementById( “spnDate"); spnDate.textContent = Date();

Using getElementById (Example) var spnDate; spnDate = document.getElementById( “spnDate"); spnDate.textContent = Date(); Variables are declared with the var keyword

Using getElementById (Example) var spnDate; spnDate = document.getElementById( “spnDate"); spnDate.textContent = Date(); Call document.getElementById() String argument containing ID of <span> tag

Using getElementById (Example) spnDate is an object with properties var spnDate; spnDate = document.getElementById( “spnDate"); spnDate.textContent = Date

Using getElementById (Example) var spnDate; spnDate = document.getElementById( “spnDate"); spnDate.textContent = Date(); textContent is a property of the <span> tag. As the name implies it stores a string

Using getElementById (Example) var spnDate; spnDate = document.getElementById( “spnDate"); spnDate.textContent = Date(); Call the JavaScript Date() function and store the result

JavaScript Functions A JavaScript function is a block of code designed to perform a particular task In the simplest case a function has the following syntax function name(){ // statements } The function keyword declares a function The function name starts with a letter and contains letters or numbers. Followed by parameters () Curly braces surround the statements to execute

JavaScript Function (Example) Declare a function named initialize()

Wiring an Event Triggers, called events fire as the user interacts with the browser and as the page loads The onload event fires after the page loads To connect an event to a function, you create and event handler

Wiring an Event Event handlers relate to an element (tag) They are implemented as element attributes The attribute key contains the event name The attribute value contains the function name The () are required Wire the initialize function to the <body>’s onload() event

Creating a First Script (Example) See JavaScriptExample1.htm Pay particular attention to the order in which the script code executes

Handling Java Incapable Browsers Include the <noscript> directive to display a message when JavaScript is disabled <html> <body> <script> document.write("Greetings") </script> <noscript> <p>JavaScript is not enabled.</p> </noscript> </body> </html>