Barb Ericson Georgia Institute of Technology May 2006

Slides:



Advertisements
Similar presentations
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Advertisements

JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
The Web Warrior Guide to Web Design Technologies
Georgia Institute of Technology JavaScript part 2 Barb Ericson Georgia Institute of Technology May 2006.
1 Javascrbipt Intro Javascript (or js) is a programming language. Interpreted, not compiled. Not the same as java, but, similar. Use tags to use. Object-oriented.
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.
Information Technology Center Hany Abdelwahab Computer Specialist.
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
Introduction to scripting
Javascript and the Web Whys and Hows of Javascript.
4.1 JavaScript Introduction
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
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.
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,
Client Side Programming with JavaScript Why use client side programming? Web sides built on CGI programs can rapidly become overly complicated to maintain,
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
 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,
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
JavaScript - A Web Script Language Fred Durao
Intro to JavaScript. Some simple examples Examples from our webpage Examples from Andrews webpage Today’s Example.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
JavaScript Syntax, how to use it in a HTML document
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.
JavaScript, Fourth Edition
CIS 375—Web App Dev II JavaScript I. 2 Introduction to DTD JavaScript is a scripting language developed by ________. A scripting language is a lightweight.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
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.
Chapter 4 Java Script - Part1. 2 Outlines Introduction to Java Script Variables, Operators and Functions Conditional statements JavaScript Objects Forms.
1 Lesson 6 Introducing JavaScript HTML and JavaScript BASICS, 4 th Edition.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript 101 Lesson 6: Introduction to Functions.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
Tarik Booker CS 120 California State University, Los Angeles.
Module 1 Introduction to JavaScript
Java Script Introduction. Java Script Introduction.
“Under the hood”: Angry Birds Maze
JavaScript is a programming language designed for Web pages.
Donna J. Kain, Clarkson University
Web Development & Design Foundations with HTML5 7th Edition
Introduction to Scripting
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
CHAPTER 4 CLIENT SIDE SCRIPTING PART 2 OF 3
Event Driven Programming & User Defined Functions
T. Jumana Abu Shmais – AOU - Riyadh
JavaScript Defined General Syntax Body vs. Head Variables Math & Logic
Functions, Regular expressions and Events
Tutorial 10 Programming with JavaScript
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
JavaScript is a scripting language designed for Web pages by Netscape.
Introduction to Programming and JavaScript
JavaScript: Introduction to Scripting
CNIT 133 Interactive Web Pags – JavaScript and AJAX
Introduction to JavaScript
Barb Ericson Georgia Institute of Technology May 2006
Presentation transcript:

Barb Ericson Georgia Institute of Technology May 2006 JavaScript part 1 Barb Ericson Georgia Institute of Technology May 2006 Georgia Institute of Technology

Georgia Institute of Technology Learning Goals Computing Concepts Recognize computing concepts in another programming language Variables, conditionals, iteration, functions Learn a bit about user interface elements Buttons, text fields, text areas, radio buttons, dialog boxes Learn a bit about handling user events onClick, onMouseOver, onMouseOut, onMouseMove Georgia Institute of Technology

Georgia Institute of Technology JavaScript isn't Java JavaScript is a different language than Java JavaScript looks much like Java, but there are differences JavaScript is a programming language that is embedded in Web pages Allows you to control HTML and parts of a web page JavaScript is a scripting language Often executed by an interpreter in your browser Client-side JavaScript (most common type) Can be executed by the server Server-side JavaScript Georgia Institute of Technology

Georgia Institute of Technology JavaScript Syntax Syntax is how a programming language looks How do you end a statement or expression? Java statements end with a semicolon How do you declare a variable? How do you specify a conditional? How do you specify a loop? How do you specify a block? In Java using { and } How do you declare a function (method that returns something)? Georgia Institute of Technology

Georgia Institute of Technology JavaScript Syntax End of Statement Using a semicolon is recommended, but not required Declaring a variable Just use the keyword var and then the name var count = 0; Don't specify the type like you do in Java Conditionals Use if, else if, and else just like in Java Loops Use for (init; test; change) or while(test) like Java Blocks Use {} just like in Java Georgia Institute of Technology

Declaring a Function in JavaScript Use the keyword function followed by the name and a parameter list in () function test() { document.writeln("This is a test"); } Use {} to define a block of statements Use document.writeln and document.write instead of System.println and System.print This writes to the HTML page instead of to a console window Println and writeln write out the line and end it with the new line character(s). Georgia Institute of Technology

Placing JavaScript in HTML Pages Use <script> and </script> to embed JavaScript in HTML pages Put function definitions inside the header Between <head> and </head> Put calls to functions inside the body of the HTML page Between <body> and </body> Georgia Institute of Technology

Georgia Institute of Technology Our Simple Web Page <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transition//EN" "http://wwww.w3.org/TR/html4/loose.dtd"> <html> <head> <title>The Simplest Possible Web Page</title> </head> <body> <h1>A Simple Heading</h1> <p>This is a very simple web page.</p> <p><image src="mediasources/barbara.jpg" /> </body> </html> Georgia Institute of Technology

Adding some Simple JavaScript <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transition//EN" "http://wwww.w3.org/TR/html4/loose.dtd"> <html> <head> <title>The Simplest Possible Web Page</title> <script> function test() { document.writeln("This is a test"); } </script> </head> <body> <h1>A Simple Heading</h1> <p>This is a very simple web page.</p> <p><image src="mediasources/barbara.jpg" /> <script> test() </script></p> </body> </html> Georgia Institute of Technology

Georgia Institute of Technology How Does that Work? <script> function test() { document.writeln("This is a test"); } </script> </head> <body> <h1>A Simple Heading</h1> <p>This is a very simple web page.</p> <p><image src="mediasources/barbara.jpg" /> <script> test() </script></p> Here’s a function named “test” with no inputs, that only writes out a string to the HTML page at the place it is called. Here we execute the function. Georgia Institute of Technology

You can also Insert HTML <script> function insertHead() { document.writeln("<h1>This is a test</h1>"); } </script> </head> <body> <h1>A Simple Heading</h1> <p>This is a very simple web page.</p> <p><image src="mediasources/barbara.jpg" /> </p> <script> insertHead() </script> </body> </html> Georgia Institute of Technology

Can we Display Anything Useful? Sure! Anything you can compute. Anything that you can get from built-in functions (mostly methods). There are lots of them. You don’t have to have a function either in the header You can just put the JavaScript code in-line Georgia Institute of Technology

Displaying the date and time <p>This is a very simple web page.</p> <p><image src="mediasources/barbara.jpg" /> </p> <p>This is being served to you on <script>document.write(Date()); </script></p> Georgia Institute of Technology

Georgia Institute of Technology Exercise Date is an object That has a method for giving the hours var d = new Date(); var time = d.getHours(); Modify the web page to give one of three different message depending on the time Like "Good Morning" if it is before 12, "Good Afternoon" if it is before 17 (5:00pm) and "Good Evening" if it is after 17 Georgia Institute of Technology

Georgia Institute of Technology Summary JavaScript is a scripting (interpreted) language for use in HTML pages Declare variables using var count = 0; Define functions using function name() {} Write text and HTML to the Web page using document.write or document.writeln There are built-in objects you can use document, date Georgia Institute of Technology