Introduction to Computer Programming 1. Overview of Programming and JavaScript - 1http://www.cs.cityu.edu.hk/~helena Overview of Programming and JavaScript.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

Introduction to JavaScript Module 1 Client Side JS Programming M-GO Sponsored By
The Web Warrior Guide to Web Design Technologies
Georgia Institute of Technology JavaScript part 2 Barb Ericson Georgia Institute of Technology May 2006.
(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 2. Program Structure I - 1
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
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.
(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript - 1
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.
1 Events Lect 8. 2 Event-driven Pages one popular feature of the Web is its interactive nature e.g., you click on buttons to make windows appear e.g.,
Javascript and the Web Whys and Hows of Javascript.
4.1 JavaScript Introduction
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
ULI101 – XHTML Basics (Part II) What is Markup Language? XHTML vs. HTML General XHTML Rules Block Level XHTML Tags XHTML Validation.
HTML HTML stands for "Hyper Text Mark-up Language“. Technically, HTML is not a programming language, but rather a markup language. Used to create web pages.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Internet Mark-up Languages CO32036 Part Lecture: Elementary JavaScript.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
SERVER web page repository WEB PAGE instructions stores information and instructions BROWSER retrieves web page and follows instructions Server Web Server.
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.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
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,
Introduction to HTML. What is a HTML File?  HTML stands for Hyper Text Markup Language  An HTML file is a text file containing small markup tags  The.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
JavaScript, Fourth Edition
1 JavaScript in Context. Server-Side Programming.
An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
JavaScript - A Web Script Language Fred Durao
Introduction to the Document Object Model DOM *Understand document structure manipulation *Dynamic effects in web pages *Programming, scripting, web content.
1 JavaScript
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
1 A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 4 JavaScript and.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
By Tharith Sriv. To write a web page you use: HHTML (HyperText Markup Language), AASP (Active Server Page), PPHP (HyperText Preprocessor), JJavaScript,
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 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.
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.
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.
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 Computer Programming 2. Program Structure I - 1http:// Program Structure I (Overview) Handling of Values – The.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
CSC 121 Computers and Scientific Thinking Fall Event-Driven Programming.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
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.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
Module 1 Introduction to JavaScript
Web Development & Design Foundations with HTML5
Microsoft® Office FrontPage® 2003 Training
Intro to JavaScript CS 1150 Spring 2017.
Web Development & Design Foundations with HTML5 7th Edition
JavaScript Introduction
Training & Development
JavaScript Overview By Kevin Harville.
Tutorial 10: Programming with javascript
JavaScript is a scripting language designed for Web pages by Netscape.
Introduction to Programming and JavaScript
Presentation transcript:

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 1http:// Overview of Programming and JavaScript What is Computer Programming Brief History of JavaScript JavaScript Quick Start : Put JavaScript in HTML code Control Webpage contents using JavaScript [Please switch off your phone]

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 2http:// " Human processing unit " What will you do when the phone rings? (1) event :a phone call (2) input :"Hi, I am Tom, I want to talk to you." (3) processing :  Search your memory – remember him?  Setup your answer:"Sorry, I don't know you." or "Hey …, long time no see." etc.. (4) output : say your answer … The above is one of the many many programs in our brains. How about computer programs ?

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 3http:// In this course, we are to learn Computer program ming : Computer Programming is the process of planning a sequence of steps for a computer to follow. "How good a computer program is?" Is it useful? Is it maintainable? Is it extensible?.. accurate? fast? cross-platform? What is a computer program? Computer A programmable device that can store, retrieve, and process data. Computer program A sequence of steps to be performed by a computer.

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 4http:// SharePoint DesignerInternet Explorer Example 1 - A webpage in html (Not yet a program) line break Andy Chen My name is Andy Chen. I'm from FYSE. Line 1: describes the markup language to be used. Line 2: mentions the standard for the naming of elements in the page (xmlns). (No need to memorize line 1 and line 2. Most web authoring tools automatically inserts them for you correctly.)

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 5http:// SharePoint Designer Internet Explorer Example 2 - A webpage in html (Not yet a program) Line 9: Formally we should add the alt attribute like: Then if the file (CS1301.gif) does not exist, the alt text will be shown: Hello Hello Hello. Nice to meet you !

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 6http:// Example 3 - A simple JavaScript program: Name: John Which color? Purple When the page is loaded, the user types a name and a text color. Then the page content is setup accordingly. Event Input Processing and output

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 7http:// Demo … prompt('Who?', ''); … prompt('Which color?', ''); … document.write(…);.. Explanation: The input dialogs are invoked by prompt(..). document.write(..) outputs the content in the page. Each JavaScript statement is ended with a semi-colon: ;. Let’s glance at the code (Example 3): Name: John Which color? Purple For simplicity, from now on we omit the tag and the xmlns attribue in the tag in our course materials.

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 8http:// What is JavaScript A language that allows you to write programs that are executed by a web-browser. Originally developed by Netscape as LiveScript. Renamed to JavaScript in 1995 (not related to Java). Microsoft also released JScript which is very much similar to JavaScript. In 1997, the European Computer Manufacturers Association (ECMA) brought together programmers from Netscape, Sun, Microsoft, Borland, and other interested companies to : "standardize a general purpose, cross-platform, vendor-neutral scripting language (based on JavaScript)" The standard was ECMA-262, the language called ECMAScript. JavaScript

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 9http:// Put JavaScript in HTML code (1) Event handler onclick event fires when the involved element is clicked. We can specify a handler accordingly. Example: JavaScript Quick Start : 4 ways to include JavaScript in HTML code: Welcome! Demo Function : Functions are executable code that you can call to perform some kind of operation. Quotes : '…' and "…" are interchangeable: "alert(' Welcome ');" is the same as 'alert(" Welcome ");' But, of course, it is wrong to write "…' or '…" (unmatched single / double quotes) That means, whenever the onclick event happens, the browser handles it by calling JavaScript's alert function to show "Welcome!".

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 10http:// Besides onclick, we have other similar events like onmouseover, onmouseout, onmousemove, onmousedown, onmouseup. onload event fires when "the document has just been completely loaded". Example: Demo This is a demo. Recall that: To show an image, we would have typed: Since it is always empty between the beginning tag and the ending tag, we can simply type. For example: Another similar case is line break:. Because it is not meaningful to say a beginning or an ending of a line break, so we combine as simply. These elements are called empty elements. Hello! This is a demo.

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 11http:// (2) Pseudo-URL JavaScript: Example: A normal URL : go to CityU A pseudo-URL : greeting Pretend the JavaScript to be a Uniform Resource Locator (URL) We may type Pseudo-URL JavaScript at the address bar: Put JavaScript in HTML code JavaScript Quick Start :

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 12http:// 2 more examples: A convenient calculator: Tell the date/time: However, don't type: alert("37.7"+"104.6") you will get ! Here, … + … means to concatenate 2 strings (ie. connect the text contents) Date() is a JavaScript object that gets the current date/time Put JavaScript in HTML code JavaScript Quick Start :

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 13http:// To put JavaScript code in the head or body sections (.. or.. ), we can use the.. tags. The document.write method outputs content in the page. (3) JavaScript Block :.. Demo Now, it is: document.write(Date()); [Click the refresh button to update!] Put JavaScript in HTML code JavaScript Quick Start :

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 14http:// (4) As a linked file Specify a.js file in the tag using the src attribute. Example: Put JavaScript in HTML code JavaScript Quick Start :

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 15http:// Often used to add content during page loading. ie. within and. BUT not very flexible because it must follow the sequential flow of the page. ie. we can’t indicate a specific location and write some content there. Common ways to control webpage contents using JavaScript: Hello John! document.write("Hello world !"); (1) document.write Control Webpage contents using JavaScript JavaScript Quick Start :

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 16http:// (2) innerHTML Explanation : a grouping element – one primary purpose is just to set an id to a block of text. innerHTML: the content of an element: JavaScript Quick Start : Welcome! <img src="CS1301.gif" onclick=" document.getElementById('Msg').innerHTML ='Cheers!';" /> Simplest method to change a specific location of the document Syntax: document.getElementById(' ').innerHTML = … Welcome!Cheers! Control Webpage contents using JavaScript xxxxxxxxxxxxxxxx

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 17http:// filling in text fields of a form, and popping another window. (You'll learn later!) JavaScript Quick Start : Other methods include: Control Webpage contents using JavaScript

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 18http:// Some points to note: (1) HTML (Under XHTML schema) and JavaScript are case-sensitive. Consider: HTML: body BODY  Body  onload ONLOAD  onLoad  JavaScript: alert ALERT  Alert  Explanation:void(0) is to avoid the pseudo-URL overriding the whole document with "Apple". For further explanation, please visit the course web. OR (2) To call a function, we add round brackets to enclose the input, like: alert('Hello') The brackets () are needed even if there is no input, like: Date() Example: alert ( Date ()) ; - Executes the Date() function first. Date() produces a date/time content, that becomes the input of alert( Date( ) ). (3)If we use Pseudo-URL to execute JavaScript code that evaluates to a value, we need to add void(0) at the end. Example: Pear Change the Fruit

Introduction to Computer Programming 1. Overview of Programming and JavaScript - 19http:// Summary Course Overview What is Computer Programming Brief History of JavaScript JavaScript Quick Start : 4 ways to put JavaScript in HTML code Event Handler, Pseudo-URL JavaScript,.., Linked File. Control Webpage contents using JavaScript document.write, innerHTML