(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript - 1

Slides:



Advertisements
Similar presentations
Introduction to JavaScript Module 1 Client Side JS Programming M-GO Sponsored By
Advertisements

The Web Warrior Guide to Web Design Technologies
Georgia Institute of Technology JavaScript part 2 Barb Ericson Georgia Institute of Technology May 2006.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 7 Event-Driven.
(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 2. Program Structure I - 1
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.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
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.
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.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
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.
Javascript Languages By Rapee kamoltalapisek ID:
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.
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.
JavaScript, Fourth Edition
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
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.
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES.
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.
JavaScript Challenges Answers for challenges
 Scripts that execute in response to some event  User clicking on something  Script does NOT execute as part of page loading  DOM facilities like.
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,
Introduction to Computer Programming 1. Overview of Programming and JavaScript - 1http:// Overview of Programming and JavaScript.
Understanding JavaScript and Coding Essentials Lesson 8.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
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
Introduction to JavaScript
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
JavaScript and Ajax (JavaScript Events)
Presentation transcript:

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript 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]

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript " 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 ?

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript 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.

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript Let’s glance 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

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript Demo … … … prompt ('Name:', '') ; … 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 a simple JavaScript program: Name: John Which color? Purple

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript FrontPageInternet Explorer A simple webpage in html: line break

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript 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 that 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

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript 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!".

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript Other similar events are onmouseover, onmouseout, onmousemove, onmousedown, onmouseup. onload event fires when "the document has just been completely loaded". Example: Demo Recall that: To show an image, we can type: 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. Hello!

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript (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 :

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript 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 :

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript 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 :

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript (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 :

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript 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 :

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript (2) innerHTML Explanation : a grouping element – one primary purpose is just to set an id to a block of text. 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

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript 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

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript Some points to note: (1) HTML is case-insensitive but JavaScript is 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 Q&A at 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

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript 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