New Media Production Lecture 7 Javascript

Similar documents
LECTURE-3. Exceptions JS Events. CS3101: Programming Languages: Javascript Ramana Isukapalli

Introduction to DHTML

CISH-6510 Web Application Design and Development. Overview of JavaScript. Overview

1$ 5 ! $ 6 4 * Source: 0 "!*! 0! * 8 97 ?!$ 5 0 *! 4! $ 0 : * ' () 7;7 7<7

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) What is JavaScript?

By the end of this section of the practical, the students should be able to:

Want to add cool effects like rollovers and pop-up windows?

Web Development & Design Foundations with HTML5

LECTURE-2. Functions review HTML Forms. Arrays Exceptions Events. CS3101: Scripting Languages: Javascript Ramana Isukapalli

Fundamentals of Website Development

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

Q1. What is JavaScript?

Events: another simple example

Key features. Nothing to do with java It is the Client-side scripting language Designed to add interactivity to HTML pages

The first sample. What is JavaScript?

JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore

Lecture 14. Introduction to JavaScript. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Javascript Lecture 23

Using JavaScript in a compatible way

Introduction to JavaScript

710 Index Attributes, 127 action attribute, 263 assigning, bottom attribute, domain name attribute, 481 expiration date attribute, 480 8

Programing for Digital Media EE1707. Lecture 4 JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts

Session 16. JavaScript Part 1. Reading

By the end of this section of the practical, the students should be able to:

Introduction to JavaScript, Part 2

JavaScript s role on the Web

COMS 469: Interactive Media II

Basic Uses of JavaScript: Modifying Existing Scripts

Chapter 16. JavaScript 3: Functions Table of Contents

JAVASCRIPT BASICS. Handling Events In JavaScript. In programing, event-driven programming could be a programming

Session 6. JavaScript Part 1. Reading

In addition JavaScript can be used to create images, which change automatically, or to make animated banners similar to animated GIFs.

Chapter4: HTML Table and Script page, HTML5 new forms. Asst. Prof. Dr. Supakit Nootyaskool Information Technology, KMITL

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

3Lesson 3: Functions, Methods and Events in JavaScript Objectives

Web Development & Design Foundations with HTML5, 8 th Edition Instructor Materials Chapter 14 Test Bank

Lecture 3: The Basics of JavaScript. Background. Needs for Programming Capability. Origin of JavaScript. Using Client-side JavaScript

Lecture 5. Connecting Code to Web Page Events

Place User-Defined Functions in the HEAD Section

Dynamic Web Pages - Integrating JavaScript into a SAS Web Application Caroline Bahler, ASG, Inc.

JavaScript is described in detail in many books on the subject, and there is excellent tutorial material at

IS 242 Web Application Development I

Software. Programming Languages. Types of Software. Types of Languages. Types of Programming. Software does something

Canvas & Brush Reference. Source: stock.xchng, Maarten Uilenbroek

JavaScript: Introduction, Types

link document.getelementbyid("coffee").style.borderwidth = "0px" document.getelementbyid("tea").style.borderwidth = "10px"

Book II: Advanced HTML. Developed by Donald Chase, LoudOffice.com (Version 1.

HTML User Interface Controls. Interactive HTML user interfaces. Document Object Model (DOM)

JavaScript Handling Events Page 1

DOM Primer Part 2. Contents

COSC 2206 Internet Tools. JavaScript Client-side Scripting Document Object Model

CSC Javascript

CISC 1600 Lecture 2.4 Introduction to JavaScript

Hyperlinks, Tables, Forms and Frameworks

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

Dynamic HTML becomes HTML5. HTML Forms and Server Processing. Form Submission to Web Server. DHTML - Mouse Events. CMST385: Slide Set 8: Forms

Introduction to using HTML to design webpages

Controlled Assessment Task. Question 1 - Describe how this HTML code produces the form displayed in the browser.

HTML 5 Tables and Forms

CICS 515 a Internet Programming Week 3. Mike Feeley

a.) All main headings should be italicized. h1 {font-style: italic;} Use an ordinary selector. HTML will need no alteration.

Lesson 5: Introduction to Events

Syllabus. Instructor: Alexander Clayborne, (301) ,

CE212 Web Application Programming Part 2

(Refer Slide Time: 01:40)

INTRODUCTION TO WEB DEVELOPMENT AND HTML. Lecture 13: Intro to JavaScript - Spring 2011

JavaScript!= Java. Intro to JavaScript. What is JavaScript? Intro to JavaScript 4/17/2013 INTRODUCTION TO WEB DEVELOPMENT AND HTML

Learning JavaScript. A C P K Siriwardhana, BSc, MSc

LAB MANUAL SUBJECT: WEB TECHNOLOGY CLASS : T.E (COMPUTER) SEMESTER: VI

A340 Laboratory Session #5

CHAPTER 6 JAVASCRIPT PART 1

Client vs Server Scripting

Dynamism and Detection

JavaScript code is inserted between tags, just like normal HTML tags:

Web Site Development with HTML/JavaScrip

What Is JavaScript? A scripting language based on an object-orientated programming philosophy.

Question No: 2 ( Marks: 1 ) - Please choose one Which of these is the correct HTML code for creating a reset button?

JS Tutorial 3: InnerHTML Note: this part is in last week s tutorial as well, but will be included in this week s lab

5. JavaScript Basics

DC71 INTERNET APPLICATIONS JUNE 2013

JavaScript. Asst. Prof. Dr. Kanda Saikaew Dept. of Computer Engineering Khon Kaen University

JavaScript Introduction

Javascript. A key was pressed OR released. A key was released. A mouse button was pressed.

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

Spring 2014 Interim. HTML forms

Web Engineering (Lecture 06) JavaScript part 2

Beijing , China. Keywords: Web system, XSS vulnerability, Filtering mechanisms, Vulnerability scanning.

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)

Shwetank Kumar Gupta

Lesson 1: Writing Your First JavaScript

So don t copy files or photocopy - Share! Share these FREE Courses! End User License Agreement Use of this package is governed by the following terms:

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

EVENT-DRIVEN PROGRAMMING

JSF - H:PANELGRID. JSF Tag. Rendered Output. Tag Attributes. The h:panel tag renders an HTML "table" element. Attribute & Description.

<form>. input elements. </form>

Loops/Confirm Tutorial:

Transcription:

New Media Production Lecture 7 Javascript

Javascript Javascript and Java have almost nothing in common. Netscape developed a scripting language called LiveScript. When Sun developed Java, and wanted Netscape to support it in Netscape Navigator. Netscape then took advantage of all the press that Java was receiving, and called there client-side scripting JavaScript. Microsoft saw the popularity of Javascript, and then created there own version for Internet Explorer called Jscript. It works much the same way, but not exactly the same.

What Javascript Can Do Can create a more interactive web experience. Highlight buttons when the user moves the mouse over a button. Can make sure users enter valid information in a web form. Javascript can do calculations on the client-side, such as dates, numbers, and conversions. Has the ability to create custom HTML pages on the fly, based on the actions a user takes. Javascript can detect which web browser is being used.

What Javascript Can Not Do JavaScript does not allow the reading or writing of files on the client machine. Prevents dangerous code from interacting with your hard disk, or from writing viruses on to your computer, or from manipulating your personal file. JavaScript does not allow the reading or writing of files on a server machine. (such as apage counts) That would need to be done with a CGI script. JavaScript can not close a window it has not opened. JavaScript cannot read information from an opened Web page that came from another server. It can not get information about where you have been surfing.

Object-Oriented JavaScript is an Object-Oriented language. Objects: An object is a thing. A cat, a computer and a bicycle are objects in the world. To JavaScript, there are objects it deals with in web browsers, such as windows, and forms, and the elements of the form, such as buttons and checkboxes. Because you can have more than one cat, or more than one window, it makes sense to give them names.

Properties Objects have properties. A cat has fur, the computer a keyboard, and the bicycle has wheels. In JavaScript, a window has a title, and a form can have a checkbox. Changing a property of an object can modify the object, and the same property can apply to completely different objects. Example: a property called empty. You can use empty where ever it applies. A cat's stomach is empty, and the cat's bowl is empty. Note that the computer's keyboard is not only properties, but also objects in their own right, which can have their own properties.

Methods Things that objects can do are called methods. Cats purr, computers crash, and bicycles roll. JavaScript objects also have methods: buttons click( ), windows open( ), and text can be selected( ). * Think of objects and properties as nouns, and methods as verbs. The nouns are things, and methods are actions that those things can do, or have done to them.

Dot Syntax Putting together objects, properties, and methods to get a better description of an object, or to describe a process. In JavaScript these are separated by periods. (also known as dots) - Dot Syntax Examples: bicycle.wheels cat.paws.front.left document.images.name window.status Examples of objects and methods in dot syntax: cat.purr( ) document.write( ) forms.elements.radio.click( )

Handling Events Events are actions that the user performs while visiting your page. Submitting a form and moving a mouse over an image are two examples. JavaScript deals with events using commands called event handlers. For example: our cat handles the event onpetting by performing the actions purr and stretch. If the user clicks on a button, the onclick event handler will take note of the action and perform whatever duties it was assigned.

Event Handlers Event onabort onblur onchange onclick onerror onfocus onload onmouseover onmouseout onselect onsubmit onunload What It Handles The user aborted loading the page The user left the object The user changed the object The user clicked on an object The script encountered an error The user made an object active The object finished loading The cursor moved over an object The cursor moved off an object The user selected the contents of an object The user submitted a form The user left the window

<html> <head> <title>javascript Hello World</title> </head> <body> <h1> </h1> <script langauge="javascript" type="text/javascript"> /* this is a comment in javascript - automatic script*/ document.write("hello, world!") </script> </body> </html>

<html> <head> <title>javascript Date</title> </head> <body> <h1> <script language="javascript" type="text/javascript"> /* this is a comment in javascript - automatic script*/ document.write(date()) </script> </h1> </body> </html>

<html> <head> <title>javascript OnClick Time</title> </head> <body> <!--triggering a script --> <p>what <a href="time.html" onclick="alert('today is '+Date())"> time</a> is it?</a></p> </body> </html>

Javascript Rollovers cached images Pop Up Windows Browser detection Slide Show Random Images Email Validation

Linking to an External Script <script type="text/javascript" language="javascript" src="loadimages.js"> </script> Placed in the head of the document.

Rollovers - Images Cached (Place this code in the head) <script type="text/javascript" language="javascript"> off1 = new Image(206,300) off1.src = "images/a1off.jpg" on1 = new Image(206,300) on1.src = "images/a1on.jpg" </script>

Rollovers - Images Cached (Place this code in the body) <a href="http://www.robertspahr.com" onmouseover="document.robpic.src=on1.src" onmouseout="document.robpic.src=off1.src"> <img src="images/a1off.jpg" name="robpic" border="0" width="206" height="300"> </a>

Lab Exercise Creating a rollover image using javascript Create a second rollover image using CSS view the example linked off the syllabus

Pop Up Windows <a href="javascript:location='popup.html'; window.open('pop1.html', 'popup', 'height=300, width=400, scrollbars=yes, status=yes,')">pop Up window</a>

Back and Close Window Back: <a href="javascript: history.go(-1)"><< Back</a> Close Window: <a href=javascript:window.close(1)>close Window</a>

Lab Exercise Creating a Pop Up Window

Browser Detection <script type="text/javascript" language="javascript"> <!-- Hide script from old browsers if (navigator.appname == "Netscape") { document.write("you're running a Netscape browser") else { if (navigator.appname == "Microsoft Internet Explorer") { document.write("you're running Internet Explorer") else { document.write("not running Netscape or I.E., thanks for thinking different!") // End hiding script from old browsers --> </script>

Slide Show - part 1 <script language="javascript" type="text/javascript"> <!-- Hide script from old browsers mypix = new rray("images/cruft1.jpg","images/cruft2.jpg","images/cruft3.jpg","images/cruft4.jpg","i ages/cruft5.jpg","images/cruft6.jpg") thispic = 0 imgct = mypix.length - 1 function chgslide(direction) { if (document.images) { thispic = thispic + direction if (thispic > imgct) { thispic = 0 if (thispic < 0) { thispic = imgct document.mypicture.src=mypix[thispic] // End hiding script from old browsers --> </script>

Slide Show part 2 <p><img src="images/cruft1.jpg" name="mypicture" width="432" height="286" alt="slideshow" /></p> <a href="javascript:chgslide(-1)"><< Previous</a> <a href="javascript:chgslide(1)">next >></a>

Lab Exercise Creating a Slide Show

Random Images <script language="javascript"> //Random Images and Links function random_imglink(){ var randomimages=new Array() //specify random images You can have as many as you wish randomimages[1]="images/cruft1_thumb.jpg" randomimages[2]="images/cruft2_thumb.jpg" //specify corresponding links below var imagelinks=new Array() imagelinks[1]="cruft1.html" imagelinks[2]="cruft2.html" var num=math.floor(math.random()*randomimages.length) if (num==0) num=1 document.write('<a href='+'"'+imagelinks[num]+'"'+'><img src="'+randomimages[num]+'" border=0></a>') random_imglink() </script>

Lab Exercise Creating a Random Images

Email Validation 1 of 3 <script language="javascript" type="text/javascript"> function validemail(email) { invalidchars = " /:,;" if (email == "") { return false for (i=0; i<invalidchars.length; i++) { badchar = invalidchars.charat(i) if (email.indexof(badchar,0) > -1) { return false atpos = email.indexof("@",1) if (atpos == -1) { return false if (email.indexof("@",atpos+1) > -1) { return false periodpos = email.indexof(".",atpos) if (periodpos == -1) { return false if (periodpos+3 > email.length) { return false return true

Email Validation - 2 of 3 function submitit(carform) { if (! validemail(carform.emailaddr.value)) { alert("invalid email address") carform.emailaddr.focus() carform.emailaddr.select() return false return true // End hiding script --> </script>

Email Validation - 3 of 3 <form onsubmit="return submitit(this)" action="???" name="myform"> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td align="right"> <b>email Address:</b> </td> <td> <input name="emailaddr" type="text" size="30" /> </td> </tr> <tr> <td height="25" colspan="2"> </td> </tr> <tr> <td> </td> <td> <p> <input type="submit" value="submit" /> <input type="reset" /></p> </td> </tr> </table> </form>