Barb Ericson Georgia Institute of Technology May 2006

Slides:



Advertisements
Similar presentations
Chapter 08: Adding Adding Interactivity Interactivity With With Behaviors Behaviors By Bill Bennett Associate Professor MSJC CIS MVC.
Advertisements

Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
Georgia Institute of Technology JavaScript part 2 Barb Ericson Georgia Institute of Technology May 2006.
JavaScript (Part 2) CS 183 4/13/2010. JavaScript (Part 2) Will cover: ◦ For.. In ◦ Events ◦ Try.. Catch, Throw ◦ Objects.
NAMEd anchors Enabling users to jump to specific points within Web documents.
20-Jun-15 JavaScript and HTML Simple Event Handling.
Information Technology Center Hany Abdelwahab Computer Specialist.
Computer Science 103 Chapter 4 Advanced JavaScript.
(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript - 1
Web Programming Material From Greenlaw/Hepp, In-line/On-line: Fundamentals of the Internet and the World Wide Web 1 Introduction The JavaScript Programming.
UNIT 6 JAVASCRIPT EVENT HANDLERS &WEB BROWSERS DETECTION.
JS: DOM Form Form Object Form Object –The Form object represents an HTML form. –For each instance of a tag in an HTML document, a Form object is created.
HTML Forms/Events (Instructor Lesson) The Event model HTML Forms Custom Events 1.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
Chapter 19: Adding JavaScript
Internet Mark-up Languages CO32036 Part Lecture: Elementary JavaScript.
JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client.
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.
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.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
Intro to JavaScript Scripting language –ECMAScript compliant –Client side vs. server side Syntactic rules –White space –Statement end: ; optional –Comments:
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
1 JavaScript 2 JavaScript. 2 Rollovers Most web page developers first use JavaScript for rollovers A rollover is a change in the appearance of an element.
Event JavaScript's interaction with HTML is handled through events that occur when the user or browser manipulates a page. When the page loads, that is.
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
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,
Active X – Mouse Events. Structured Graphics Control  Included in Internet Explorer v5.0  Add to page with the OBJECT tag  Accessible via scripting.
IS2802 Introduction to Multimedia Applications for Business Lecture 3: JavaScript and Functions Rob Gleasure
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Making dynamic pages with javascript Lecture 1. Java script java versus javascript Javascript is a scripting language that will allow you to add real.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
Project 8: Reacting to Events Essentials for Design JavaScript Level One Michael Brooks.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
COS 125 DAY 20. Agenda Assignment 8 not corrected yet Assignment 9 posted  Due April 16 New course time line Discussion on Scripts 
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
JavaScript Functions A function is a block of code that can be reused. It is similar to a method in Java. It consists of a function name, an argument.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
5 th and 4 th ed: some from chapters 9, 12, 13 SY306 Web and Databases for Cyber Operations Slide Set #8: Dynamic HTML.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
JavaScript Events.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
Functions Wouldn’t it be nice to be able to bring up a new animal and paragraph without having to reload the page each time? We can! We can place the.
WEB SYSTEMS & TECHNOLOGY. Java Script  JavaScript created by Netscape  It is also client side programming  It can be use for client side checks.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
Third lecture Event 27/2/2016 JavaScript Tutorial.
JavaScript and HTML Simple Event Handling 11-May-18.
Introduction to JavaScript Events
JavaScript (JS) Basics
Barb Ericson Georgia Institute of Technology May 2006
Web Development & Design Foundations with HTML5 7th Edition
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript and HTML Simple Event Handling 19-Sep-18.
JavaScript Events.
Your 1st Programming Assignment
Conditionally Confirming a Submit
JavaScript Intro.
JavaScript and Ajax (JavaScript Events)
Web Programming and Design
Web Programming and Design
Web Programming and Design
Introduction to Web programming
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

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

Georgia Institute of Technology Learning Goals Computing Concepts How to do loops in JavaScript JavaScript operators How to use dialogs in JavaScript How to handle events in JavaScript Georgia Institute of Technology

Georgia Institute of Technology Using Loops <html> <head> <title>The Simplest Possible Web Page</title> <script> function countToTen() { document.write("<ul>"); for (i=1; i<= 10; i++) { document.write("<li>Item number: ",i); } document.write("</ul>"); </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> countToTen() </script> </body> </html> Georgia Institute of Technology

Explaining that Function function countToTen() { document.write("<ul>"); for (i=1; i<= 10; i++) document.write("<li>Item number: ",i); } document.write("</ul>"); We can write out <ul> and </ul> Creating an item for each value of i Georgia Institute of Technology

Georgia Institute of Technology Explaining that Loop for (i=1; i<= 10; i++) { document.write("<li>Item number: ",i); } A for loop has three parts, separated by semi-colons. What to do first. set i to 1 When to do the body i<=10 What to do each time through the loop i++ means to increment the value of i by 1. It’s a notation that was invented by the programming language C and has been adopted by many languages Georgia Institute of Technology

Operators in JavaScript The same kind of operators you know in Java + - * / + even works for strings, as well as numbers < <= > >= == and != ! for not Logical operators are a little weird && is AND || is OR Georgia Institute of Technology

Using Dialogs in JavaScript function check() { var agree = false; agree = confirm('Do you enjoy CS?'); if (agree) notes=prompt("Give me one good thing about CS:"); if (!agree) notes=prompt("Why don't you like CS?"); alert("You said:"+notes); } … <script> check() </script> </body> </html> agree will be true or false. !agree is not agree. Notice: We can indent or not indent as we want here. Indentation is not important in JavaScript (or most other languages, except to the reader) Georgia Institute of Technology

What Happens When this Runs Georgia Institute of Technology

Different kinds of dialogs Confirm: Puts up a prompt, returns true or false. Alert: Beeps and displays one thing with an OK button. No return. Prompt: Asks the user for a line of text. Returns that text. Georgia Institute of Technology

Running on Loading the Page This program runs when the page loads. Is that what you really want to happen? The user sees nothing at all until they go to your page and then these dialog boxes happen. Isn’t it more natural for dialog boxes to pop up when you click on something? Georgia Institute of Technology

Events: Key to responding to users The key to responding to users are events. Events are actions taken by the user that can be caught by your program in JavaScript. Events are caused by the user typing a key, moving the mouse, clicking the mouse, and so on. Georgia Institute of Technology

Georgia Institute of Technology Events in JavaScript onKeyPress onKeyUp onKeyDown onClick onDblClick onMouseOver onMouseOut onMouseMove onMouseDown onMouseUp onChange (for text fields) onLoad And many, many more Some of them depend on the type of browser. Georgia Institute of Technology

Georgia Institute of Technology Catching an event On appropriate tags, assign the event to some JavaScript code in a string. Most of these can be used with anchor or image tags. onLoad can be used with the <body> tag. onChange can be used with text fields. We haven’t seen them yet. Georgia Institute of Technology

Georgia Institute of Technology Example Event Code <body> <h1>A Simple Heading</h1> <p>This is a very simple web page.</p> <p><image src="mediasources/barbara.jpg" onClick='alert("You clicked me!")' /> </p> </body> Georgia Institute of Technology

Georgia Institute of Technology Exercise Create a web page that has a button in it and when you click on the button change the background color of the button Or show a dialog box that says you clicked on the button Create a Web page that has a button on it and each time you click the button update the page to show the number of times you have clicked the button Or use a dialog to show the number of times Create a Web page with radio buttons on it and change the text that is displayed based on which button has been clicked Or use a dialog to show which radio button has been clicked Georgia Institute of Technology

Georgia Institute of Technology Summary JavaScript loops are like Java's loops For and while loops JavaScript operators are like Java's operators Except for AND and OR There are three types of dialogs in JavaScript Confirm, alert and prompt You can respond to user events Like onClick, onChange, onMouseMove Georgia Institute of Technology