Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall Project #1, Exam #1, old homework

Size: px
Start display at page:

Download "Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall Project #1, Exam #1, old homework"

Transcription

1 Lecture 16 Javascript Announcements Project #1, Exam #1, old homework Wendy Cooper 312 MTuThFr 10-3; or other times if I am in 310 Project #2 Submit a single PDF by mail or a printout in person Get JavaScript by Example Most examples in book on class website Exam#2 11/10 (Review 11/4) 1

2 Vote Today!!!!! eval( ) method The eval() function evaluates a string and executes it as if it was script code. If there is no result, undefined is returned W3C example Quigley example 2

3 The return Statement The return statement is used to specify the value that is returned from the function. So, functions that are going to return a value must use the return statement. This W3C example returns the product of two numbers (a and b) Another W3C example -- passing a parameter Another W3c example Scope reminder If you declare a variable within a function, the variable can only be accessed within that function. When you exit the function, the variable is destroyed. Scope reminder If you declare a variable within a function, the variable can only be accessed within that function. When you exit the function, the variable is destroyed. <html> example <head> <script type="text/javascript"> Function product(a,b) { var a=15; a 15 return a*b; </head> <body> <script type="text/javascript"> var a=4; document.write(product(a,3)); document.write("<br>",a); </body> </html> a gets the value of a (4), b 3 3

4 Operators Because most JavaScript syntax is borrowed from C (and is therefore just like Java), we won t spend much time on it Arithmetic operators (all numbers are floating-point): + - * / % Comparison operators: < <= ==!= >= > Logical operators: &&! (&& and are short-circuit operators) Bitwise operators: & ^ ~ << >> >>> Assignment operators: += -= *= /= %= <<= >>= >>>= &= ^= = Conditional Statements Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this. In JavaScript we have the following conditional statements: if statement - use this statement if you want to execute some code only if a specified condition is true example if...else statement - use this statement if you want to execute some code if the condition is true and another code if the condition is false example if...else if...else statement - use this statement if you want to select one of many blocks of code to be executed example switch statement - use this statement if you want to select one of many blocks of code to be executed example 4

5 JavaScript Loops Often when you write code, you want the same block of code to run over and over again in a row. Instead of adding several almost equal lines in a script we can use loops to perform a task like this. In JavaScript there are two different kind of loops: for - loops through a block of code a specified number of time for (var=startvalue;var<=endvalue;var=var+increment) { code to be executed while - loops through a block of code while a specified condition is true while (var<=endvalue) { code to be executed For loop Example This W3C example defines a loop that starts with i=0. The loop will continue to run as long as i is less than, or equal to 5. i will increase by 1 each time the loop runs. Note: The increment parameter could also be negative, and the <= could be any comparing statement. 5

6 The while loop Example This W3C example defines a loop that starts with i=0. The loop will continue to run as long as i is less than, or equal to 5. i will increase by 1 each time the loop runs: The do/while loop Executes the body of the loop at least once before testing its condition example 6

7 Quigley Examples for loop example while loop example Nested loops <html> <head> <title>nested loops</title> </head> <body> <script language=javascript> <!-- Hiding JavaScript from old browsers var str = "@"; for ( var row = 0; row < 6; row++){ for ( var col=0; col < row; col++){ document.write(str); document.write("<br>"); //--> </body> </html> 7

8 Nested loops for ( var row = 0; row < 6; row++){ document.write("<br>"); row = 0 <br> row = <br> row and so on for ( var col=0; col < row; col++){ document.write(str); col= 0 row col=0 <row col= 1 row col=0 <row col= 1 < row example break and continue The break Statement will break the loop and continue executing the code that follows after the loop (if any) example The continue Statement will break the current loop and continue with the next value example 8

9 Events JavaScript helps create dynamic web pages Events are actions that can be detected by JavaScript every element on a web page has certain events which can trigger a JavaScript onclick event of a button element to call a function when a user clicks on the button. the function will not be executed before the event occurs! Examples of events: A mouse click A UNIVERSITY web OF page MASSACHUSETTS or an image AMHERST loading CMPSCI 120 Fall 2010 Mousing over a hot spot on the web page Event Handlers 9

10 onload and onunload are triggered when the user enters or leaves the page often used to deal with cookies that should be set when a user enters or leaves a page. e.g., you could have a popup asking for the user's name upon his first arrival to your page. The name is then stored in a cookie. Next time the visitor arrives at your page, you could have another popup saying something like: "Welcome John Doe!" onload event often used to check the visitor's browser type and browser version, and load the proper version of the web page based on the information. onfocus, onblur and onchange are often used in combination with validation of form fields. onblur An element loses focus onchange The user changes the content of a field onfocus An element gets focus Here the check () function will be called whenever the user changes the content of the field: <input type="text" size="30" id=" " onchange="check ()"> 10

11 onmouseover and onmouseout onmouseover and onmouseout are often used to create "animated" buttons. example <a href=" onmouseover="alert('an onmouseover event');return false"><img src="w3s.gif" alt="w3schools" /></a> JavaScript is not Java So far we have talked about things that are the same as in Java, but JavaScript also has some features that resemble features in Java: JavaScript has Objects and primitive data types JavaScript has qualified names; for example, document.write("hello World"); JavaScript has Events and event handlers Exception handling in JavaScript is almost the same as in Java 11

12 JavaScript is not Java JavaScript has some features unlike anything in Java: Variable names are untyped: the type of a variable depends on the value it is currently holding Objects and arrays are defined in quite a different way JavaScript has with statements and a new kind of for statement Warnings JavaScript is a big, complex language So far, only scratched the surface It s easy to get started in JavaScript, but if you need to use it heavily, plan to invest time in learning it well Write and test your programs a little bit at a time 12

13 Warnings JavaScript is not totally platform independent Expect different browsers to behave differently Write and test your programs a little bit at a time Browsers aren t designed to report errors Don t expect to get any helpful error messages Object Orientation - concepts Class defines the abstract characteristics of a thing (object), including its attributes, fields or properties and its behaviors Object/Instance a pattern (exemplar) of a class that consists of state and behavior that's defined in the object's class Message passing process by which an object sends data to another object or asks the other object to invoke a method. A Few JavaScript Objects window document form image A Few JavaScript Methods alert() write() focus() A Few JavaScript Properties href (url string) bgcolor value (in a form text field) src (path & filename of an image) 13

14 JavaScript and objects Start with built-in JavaScript objects Objects are a form of data methods for examing properties of datatypes we create and methods for manipulating these. Properties are the values associated with an object. <script type="text/javascript"> var txt="hello World!"; document.write(txt.length); The output of the code above will be: 12 Object string is associated with string datatypes, Declaring a variable by assigning a string to it, in effect invokes the constructor var txt=new String(); JavaScript and objects Methods are the actions that can be performed on (or by) objects. using the touppercase() method of the String object to display a text in uppercase letters: <script type="text/javascript"> var str="hello world!"; document.write(str.touppercase()); The output of the code above will be: HELLO WORLD! 14

15 Three ways to create an object 1. You can use an object literal: var course = {number: "CIT597",teacher: "Dr. Dave" 2. You can use new to create a blank object, and add fields to it later: var course = new Object(); course.number = "CIT597"; course.teacher = "Dr. Dave"; Three ways to create an object 3. You can write and use a constructor: function Course(n, t) { // best placed in <head> this.number = n;// keyword "this" is required, not optional this.teacher = t; var course = new Course("CIT597", "Dr. Dave"); You don t declare the types of variables in JavaScript 15

16 W3C Try it Yourself - Examples using the string object to style strings Style strings use the indexof() method to return the position of the first occurrence of a specified string value in a string The indexof() method use the match() method to search for a specified string value within a string and return the string value if found The match() method use the replace() method to replace some characters with some other characters in a string The replace() method The Array Object to create an Array object called mycars: var mycars=new Array(); There are two ways of adding values to an array (you can add as many values as you need to define as many variables you require). Option 1: var mycars=new Array(); mycars[0]="saab"; mycars[1]="volvo"; mycars[2]="bmw"; You could also pass an integer argument to control the array's size: var mycars=new Array(3); mycars[0]="saab"; mycars[1]="volvo"; mycars[2]="bmw"; Option 2: var mycars=new Array("Saab","Volvo","BMW"); Note: If you specify numbers or true/false values inside the array then the type of variables will be numeric or Boolean instead of string You can refer to a particular element in an array by referring to the name of the array and the index number. The index number starts at 0. document.write(mycars[0]); 16

17 Manipulating the array object How to use a for...in statement to loop through the elements of an array. For...In Statement from W3C An example from Quigley an array of strings <script language="javascript"> var book = new Array(6); // Create an Array object book[0] = "War and Peace"; // Assign values its elements book[1] = "Huckleberry Finn"; book[2] = "The Return of the Native"; book[3] = "A Christmas Carol"; book[4] = "The Yearling"; book[5] = "Exodus"; for(var i in book){ document.write("book[" + i + "] "+ book[i] + "<br>"); Manipulating the array object An example from Quigley an array of numbers <html><head><title>the Array Object</title><body> <body> <h2>an Array of Numbers</h2> <script language="javascript"> var years = new Array(10); for(var i=0; i < years.length; i++ ){ years[i]=i ; document.write("years[" + i + "] = "+ years[i] + "<br>"); </body> </html> 17

18 Manipulating the array object An Example from JSBE9.4 - Associative arrays <html><head><title>associative Arrays</title></head> <body> <h2>an Array Indexed by Strings</h2> <script language="javascript"> var states = new Array(); states["ca"] = "California"; states["me"] = "Maine"; states["mt"] = "Montana"; for( var i in states ){ document.write("the index is:<em> "+ i ); document.write(".</em> The value is: <em>" + states[i] + ".</em><br>"); </body> </html> Array properties & methods W3C W3C mod Q9.7 Q9.8 18

19 Manipulating the array object How to shift, unshift and slice JSBE 9.9 and 9.10 How to use the sort() method to sort a literal array. Literal array - sort() How to use the sort() method to sort a numeric array. Numeric array - sort() The Date Object get today's date. Return today's date and time used to work with dates and times. var mydate=new Date() will automatically hold the current date and time as its initial value! set Dates var mydate=new Date(); mydate.setfullyear(2010,0,14); set a Date object to be 5 days into the future: var mydate=new Date(); mydate.setdate(mydate.getdate()+5); Note: If adding five days to a date shifts the month or year, the changes are handled automatically by the Date object itself! 19

20 Date object methods Use gettime() to calculate the years since 1970 gettime Use getday() and an array to write a weekday, and not just a number. getday() Compare Two Dates & more var mydate=new Date(); mydate.setfullyear(2010,0,14); var today = new Date(); if (mydate>today) { alert("today is before 14th January 2010"); else { alert("today is a:er 14th January 2010"); 20

21 More date object manipulations prototype Quigley 9.13, 9.14 How to display a clock on your web page Display a clock Using the prototype property to extend the capabilities of the date object 9.15 function weekday(){ var now = this.getday(); var names = new Array(7); names[0]="sunday";... names[6]="saturday"; return(names[now]); Date.prototype.DayOfWeek=weekDay; In <head> </head> var today=new Date(); In <body> </body> document.write("today is " + today.dayofweek() + ".<br>"); Math Object The Math object allows you to perform mathematical tasks. includes several mathematical constants and methods. is not a constructor. All properties and methods of Math can be called by using Math as an object without creating it. Syntax for using properties/methods of Math var pi_value=math.pi; var sqrt_value=math.sqrt(16); 21

22 math object properties var pi_value=math.pi; math object methods var sqrt_value=math.sqrt(16); Q9.17 max() min() round() Q

23 User defined objects new operator used to create an instance of an object var car= new Object() var friends = new Array( Tom, Dick, Mary ) var now = new Date( July 4, 1776) Object constructor A function (or a method) that creates and initializes an object var car= new Object() creates a reference to the object but properties and methods are not defined with var Example (Q8.3) <html> <head><title>user-defined objects</title> <script language = "javascript"> var toy = new Object(); // Create the object toy.name = "Lego"; // Assign properties to the object toy.color = "red"; toy.shape = "rectangle"; </head> <body bgcolor="lightblue"> <script language = "javascript"> document.write("<b>the toy is a " + toy.name + "."); document.write("<br>it is a " + toy.color + " " + toy.shape+ "."); </body> </html> 23

24 Creating an object with a function (Q8.4) <html> <head><title>user-defined objects</title></head> <script language = "javascript"> function book(title, author, publisher){ // Defining properties this.title = title; this.author = author; this.publisher = publisher; <body bgcolor="lightblue"></body> <script language = "javascript"> var mybook = new book("javascript by Example", "Ellie", "Prentice Hall"); document.writeln("<b>" + mybook.title + "<br>" + mybook.author + "<br>" + mybook.publisher ); </body> </html> Defining methods <html> <head><title>simple Methods</title> <script language = "javascript"> function distance(r, t){ // define the object this.rate = r; // assign properties this.time = t; function calc_distance(){ // define a function that will // be used as a method return this.rate * this.time; </head> <body bgcolor="lightblue"> <script language="javascript"> var speed=eval(prompt("what was your speed (miles per hour)? ","")); var elapsed=eval(prompt("how long did the trip take (hours)?","")); var howfar=new distance(speed, elapsed); // call the constructor howfar.distance=calc_distance; // create a new property var d = howfar.distance(); // invoke method alert("the distance is " + d + " miles."); </body> </html>

25 More Examples Method defined in a constructor 8.6 More Examples JSBE8.9 the with keyword <script language = "javascript"> function book(title, author, publisher){ this.title = title; // properties this.author = author; this.publisher = publisher; this.show = display; // Define a method function display(anybook){ with(this){ // The with keyword var info = "The title is " + title; info += "\nthe author is " + author; info += "\nthe publisher is " + publisher; alert(info); </head> <body bgcolor="lightblue"> <script language = "javascript"> var childbook = new book("a Child's Garden of Verses","Robert Lewis Stevenson", "Little Brown"); var adultbook = new book("war and Peace", "Leo Tolstoy","Penguin Books"); childbook.show(childbook); // call method for child's book adultbook.show(adultbook); // call method for adult s book </body> </html> 25

26 Recursion - computing factorials n! = n x n-1 x n-2 x. x 2 x 1 Using a for loop 0!=1 function fact(n) 3! = 3*2*1 = 6 { 5! = 5*4*3*2*1 = 120 var n, nfac=1; for(i=n;i>0;i--) { nfac=nfac*i; document.factorialinput.nfac.value = nfac example 8! = 8*7*6*5*4*3*2*1 = Recursion - computing factorials n! = n x n-1 x n-2*. x 2 x 1 Using recursion <script type="text/javascript"> function factorial(n) { if ((n == 0) (n == 1)) return 1 else { result = (n * factorial(n-1) ) return result example 26

The first sample. What is JavaScript?

The first sample. What is JavaScript? Java Script Introduction JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Firefox, Chrome, Opera, and Safari. In this lecture

More information

Introduction to JavaScript

Introduction to JavaScript 127 Lesson 14 Introduction to JavaScript Aim Objectives : To provide an introduction about JavaScript : To give an idea about, What is JavaScript? How to create a simple JavaScript? More about Java Script

More information

Q1. What is JavaScript?

Q1. What is JavaScript? Q1. What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight programming language JavaScript is usually embedded

More information

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010 Lecture 15 Javascript Announcements Project #1 Graded VG, G= doing well, OK = did the minimum, OK - = some issues, do better on P#2 Homework #6 posted, due 11/5 Get JavaScript by Example Most examples

More information

Session 16. JavaScript Part 1. Reading

Session 16. JavaScript Part 1. Reading Session 16 JavaScript Part 1 1 Reading Reading Wikipedia en.wikipedia.org/wiki/javascript / p W3C www.w3.org/tr/rec-html40/interact/scripts.html Web Developers Notes www.webdevelopersnotes.com/tutorials/javascript/

More information

Session 6. JavaScript Part 1. Reading

Session 6. JavaScript Part 1. Reading Session 6 JavaScript Part 1 Reading Reading Wikipedia en.wikipedia.org/wiki/javascript Web Developers Notes www.webdevelopersnotes.com/tutorials/javascript/ JavaScript Debugging www.w3schools.com/js/js_debugging.asp

More information

COMS 469: Interactive Media II

COMS 469: Interactive Media II COMS 469: Interactive Media II Agenda Review Ch. 5: JavaScript An Object-Based Language Ch. 6: Programming the Browser Review Data Types & Variables Data Types Numeric String Boolean Variables Declaring

More information

CSS The web browser uses its own resources, and eases the burden on the server. It has fewer features than server side scripting.

CSS The web browser uses its own resources, and eases the burden on the server. It has fewer features than server side scripting. What is JavaScript? HTML and CSS concentrate on a static rendering of a page; things do not change on the page over time, or because of events. To do these things, we use scripting languages, which allow

More information

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

LECTURE-2. Functions review HTML Forms. Arrays Exceptions Events. CS3101: Scripting Languages: Javascript Ramana Isukapalli LECTURE-2 Functions review HTML Forms Arrays Exceptions Events 1 JAVASCRIPT FUNCTIONS, REVIEW Syntax function (params) { // code Note: Parameters do NOT have variable type. 1. Recall: Function

More information

CGS 3066: Spring 2015 JavaScript Reference

CGS 3066: Spring 2015 JavaScript Reference CGS 3066: Spring 2015 JavaScript Reference Can also be used as a study guide. Only covers topics discussed in class. 1 Introduction JavaScript is a scripting language produced by Netscape for use within

More information

Such JavaScript Very Wow

Such JavaScript Very Wow Such JavaScript Very Wow Lecture 9 CGS 3066 Fall 2016 October 20, 2016 JavaScript Numbers JavaScript numbers can be written with, or without decimals. Extra large or extra small numbers can be written

More information

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

By the end of this section of the practical, the students should be able to: By the end of this section of the practical, the students should be able to: Write JavaScript to generate HTML Create simple scripts which include input and output statements, arithmetic, relational and

More information

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

JavaScript. Asst. Prof. Dr. Kanda Saikaew Dept. of Computer Engineering Khon Kaen University JavaScript Asst. Prof. Dr. Kanda Saikaew (krunapon@kku.ac.th) Dept. of Computer Engineering Khon Kaen University 1 Why Learn JavaScript? JavaScript is used in millions of Web pages to Validate forms Detect

More information

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p. Preface p. xiii Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p. 5 Client-Side JavaScript: Executable Content

More information

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

710 Index Attributes, 127 action attribute, 263 assigning, bottom attribute, domain name attribute, 481 expiration date attribute, 480 8 INDEX Symbols = (assignment operator), 56 \ (backslash), 33 \b (backspace), 33 \" (double quotation mark), 32 \e (escape), 33 \f (form feed), 33

More information

Place User-Defined Functions in the HEAD Section

Place User-Defined Functions in the HEAD Section JavaScript Functions Notes (Modified from: w3schools.com) A function is a block of code that will be executed when "someone" calls it. In JavaScript, we can define our own functions, called user-defined

More information

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

Lecture 14. Introduction to JavaScript. Mr. Mubashir Ali Lecturer (Dept. of Computer Science) Lecture 14 Introduction to JavaScript Mr. Mubashir Ali Lecturer (Dept. of dr.mubashirali1@gmail.com 1 Outline What is JavaScript? Embedding JavaScript with HTML JavaScript conventions Variables in JavaScript

More information

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

LECTURE-3. Exceptions JS Events. CS3101: Programming Languages: Javascript Ramana Isukapalli LECTURE-3 Exceptions JS Events 1 EXCEPTIONS Syntax and usage Similar to Java/C++ exception handling try { // your code here catch (excptn) { // handle error // optional throw 2 EXCEPTIONS EXAMPLE

More information

Client-Side Web Technologies. JavaScript Part I

Client-Side Web Technologies. JavaScript Part I Client-Side Web Technologies JavaScript Part I JavaScript First appeared in 1996 in Netscape Navigator Main purpose was to handle input validation that was currently being done server-side Now a powerful

More information

What is Java Script? Writing to The HTML Document. What Can JavaScript do? CMPT 165: Java Script

What is Java Script? Writing to The HTML Document. What Can JavaScript do? CMPT 165: Java Script What is Java Script? CMPT 165: Java Script Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University November 7, 2011 JavaScript was designed to add interactivity to HTML pages

More information

5. JavaScript Basics

5. JavaScript Basics CHAPTER 5: JavaScript Basics 88 5. JavaScript Basics 5.1 An Introduction to JavaScript A Programming language for creating active user interface on Web pages JavaScript script is added in an HTML page,

More information

Just add an HTML comment tag <!-- before the first JavaScript statement, and an end-of comment tag --> after the last JavaScript statement, like this:

Just add an HTML comment tag <!-- before the first JavaScript statement, and an end-of comment tag --> after the last JavaScript statement, like this: JavaScript Basic JavaScript How To and Where To JavaScript Statements and Comments JavaScript Variables JavaScript Operators JavaScript Comparisons JavaScript If Else JavaScript Loops JavaScript Flow Control

More information

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies Internet t Software Technologies JavaScript part one IMCNE A.A. 2008/09 Gabriele Cecchetti Why introduce JavaScript To add dynamicity and interactivity to HTML pages 2 What s a script It s a little interpreted

More information

DC71 INTERNET APPLICATIONS JUNE 2013

DC71 INTERNET APPLICATIONS JUNE 2013 Q 2 (a) With an example show text formatting in HTML. The bold text tag is : This will be in bold. If you want italics, use the tag, as follows: This will be in italics. Finally, for

More information

PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore WEB PROGRAMMING Solution Set II

PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore WEB PROGRAMMING Solution Set II PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore 560 100 WEB PROGRAMMING Solution Set II Section A 1. This function evaluates a string as javascript statement or expression

More information

PIC 40A. Lecture 10: JS: Wrapper objects, Input and Output, Control structures, random numbers. Copyright 2011 Jukka Virtanen UCLA 1 04/24/17

PIC 40A. Lecture 10: JS: Wrapper objects, Input and Output, Control structures, random numbers. Copyright 2011 Jukka Virtanen UCLA 1 04/24/17 PIC 40A Lecture 10: JS: Wrapper objects, Input and Output, Control structures, random numbers 04/24/17 Copyright 2011 Jukka Virtanen UCLA 1 Objects in JS In C++ we have classes, in JS we have OBJECTS.

More information

JavaScript Introduction

JavaScript Introduction JavaScript Introduction Web Technologies I. Zsolt Tóth University of Miskolc 2016 Zsolt Tóth (UM) JavaScript Introduction 2016 1 / 31 Introduction Table of Contents 1 Introduction 2 Syntax Variables Control

More information

CITS1231 Web Technologies. JavaScript Math, String, Array, Number, Debugging

CITS1231 Web Technologies. JavaScript Math, String, Array, Number, Debugging CITS1231 Web Technologies JavaScript Math, String, Array, Number, Debugging Last Lecture Introduction to JavaScript Variables Operators Conditional Statements Program Loops Popup Boxes Functions 3 This

More information

3 The Building Blocks: Data Types, Literals, and Variables

3 The Building Blocks: Data Types, Literals, and Variables chapter 3 The Building Blocks: Data Types, Literals, and Variables 3.1 Data Types A program can do many things, including calculations, sorting names, preparing phone lists, displaying images, validating

More information

Note: Java and JavaScript are two completely different languages in both concept and design!

Note: Java and JavaScript are two completely different languages in both concept and design! Java Script: JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight programming language JavaScript is usually embedded directly

More information

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010 Lecture 14 Javascript Announcements Project #2 New website Exam#2 No. Class Date Subject and Handout(s) 17 11/4/10 Examination Review Practice Exam PDF 18 11/9/10 Search, Safety, Security Slides PDF UMass

More information

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

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh Web Programming and Design MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh Plan for the next 5 weeks: Introduction to HTML tags, creating our template file Introduction to CSS and style

More information

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

Lecture 3: The Basics of JavaScript. Background. Needs for Programming Capability. Origin of JavaScript. Using Client-side JavaScript Lecture 3: The Basics of JavaScript Wendy Liu CSC309F Fall 2007 Background Origin and facts 1 2 Needs for Programming Capability XHTML and CSS allows the browser to passively display static content How

More information

INTRODUCTION TO WEB DEVELOPMENT AND HTML. Lecture 15: JavaScript loops, Objects, Events - Spring 2011

INTRODUCTION TO WEB DEVELOPMENT AND HTML. Lecture 15: JavaScript loops, Objects, Events - Spring 2011 INTRODUCTION TO WEB DEVELOPMENT AND HTML Lecture 15: JavaScript loops, Objects, Events - Spring 2011 Outline Selection Statements (if, if-else, switch) Loops (for, while, do..while) Built-in Objects: Strings

More information

INFS 2150 Introduction to Web Development and e-commerce Technology. Programming with JavaScript

INFS 2150 Introduction to Web Development and e-commerce Technology. Programming with JavaScript INFS 2150 Introduction to Web Development and e-commerce Technology Programming with JavaScript 1 Objectives JavaScript client-side programming Example of a JavaScript program The element

More information

Objectives. Introduction to JavaScript. Introduction to JavaScript INFS Peter Y. Wu, RMU 1

Objectives. Introduction to JavaScript. Introduction to JavaScript INFS Peter Y. Wu, RMU 1 Objectives INFS 2150 Introduction to Web Development and e-commerce Technology Programming with JavaScript JavaScript client-side programming Example of a JavaScript program The element

More information

EVENT-DRIVEN PROGRAMMING

EVENT-DRIVEN PROGRAMMING LESSON 13 EVENT-DRIVEN PROGRAMMING This lesson shows how to package JavaScript code into self-defined functions. The code in a function is not executed until the function is called upon by name. This is

More information

<form>. input elements. </form>

<form>. input elements. </form> CS 183 4/8/2010 A form is an area that can contain form elements. Form elements are elements that allow the user to enter information (like text fields, text area fields, drop-down menus, radio buttons,

More information

Princess Nourah bint Abdulrahman University. Computer Sciences Department

Princess Nourah bint Abdulrahman University. Computer Sciences Department Princess Nourah bint Abdulrahman University 1 And use http://www.w3schools.com/ JavaScript Objectives Introduction to JavaScript Objects Data Variables Operators Types Functions Events 4 Why Study JavaScript?

More information

CSC Web Programming. Introduction to JavaScript

CSC Web Programming. Introduction to JavaScript CSC 242 - Web Programming Introduction to JavaScript JavaScript JavaScript is a client-side scripting language the code is executed by the web browser JavaScript is an embedded language it relies on its

More information

What is PHP? [1] Figure 1 [1]

What is PHP? [1] Figure 1 [1] PHP What is PHP? [1] PHP is an acronym for "PHP: Hypertext Preprocessor" PHP is a widely-used, open source scripting language PHP scripts are executed on the server PHP is free to download and use Figure

More information

Fundamentals of Website Development

Fundamentals of Website Development Fundamentals of Website Development CSC 2320, Fall 2015 The Department of Computer Science Events handler Element with attribute onclick. Onclick with call function Function defined in your script or library.

More information

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications JavaScript Started as a simple script in a Web page that is interpreted and run by the browser Supported by most modern browsers Allows dynamic update of a web page More generally, allows running an arbitrary

More information

JAVASCRIPT FOR PROGRAMMERS

JAVASCRIPT FOR PROGRAMMERS JAVASCRIPT FOR PROGRAMMERS DEITEL DEVELOPER SERIES Paul J. Deitel Deitel & Associates, Inc. Harvey M. Deitel Deitel & Associates, Inc. PRENTICE HALL Upper Saddle River, NJ Boston Indianapolis San Francisco

More information

Internet Technologies 5-Dynamic Web. F. Ricci 2010/2011

Internet Technologies 5-Dynamic Web. F. Ricci 2010/2011 Internet Technologies 5-Dynamic Web F. Ricci 2010/2011 Content The "meanings" of dynamic Building dynamic content with Java EE (server side) HTML forms: how to send to the server the input PHP: a simpler

More information

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan Lecture 08-1 Programming in C++ PART 1 By Assistant Professor Dr. Ali Kattan 1 The Conditional Operator The conditional operator is similar to the if..else statement but has a shorter format. This is useful

More information

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

Software. Programming Languages. Types of Software. Types of Languages. Types of Programming. Software does something Software Software does something LBSC 690: Week 10 Programming, JavaScript Jimmy Lin College of Information Studies University of Maryland Monday, April 9, 2007 Tells the machine how to operate on some

More information

The JavaScript Language

The JavaScript Language The JavaScript Language INTRODUCTION, CORE JAVASCRIPT Laura Farinetti - DAUIN What and why JavaScript? JavaScript is a lightweight, interpreted programming language with object-oriented capabilities primarily

More information

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

JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore JavaScript and XHTML Prof. D. Krupesha, PESIT, Bangalore Why is JavaScript Important? It is simple and lots of scripts available in public domain and easy to use. It is used for client-side scripting.

More information

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

Key features. Nothing to do with java It is the Client-side scripting language Designed to add interactivity to HTML pages Javascript Key features Nothing to do with java It is the Client-side scripting language Designed to add interactivity to HTML pages (DHTML): Event-driven programming model AJAX Great example: Google Maps

More information

MatchaScript: Language Reference Manual Programming Languages & Translators Spring 2017

MatchaScript: Language Reference Manual Programming Languages & Translators Spring 2017 MatchaScript: Language Reference Manual Programming Languages & Translators Spring 2017 Language Guru: Kimberly Hou - kjh2146 Systems Architect: Rebecca Mahany - rlm2175 Manager: Jordi Orbay - jao2154

More information

CISC 1600 Lecture 2.4 Introduction to JavaScript

CISC 1600 Lecture 2.4 Introduction to JavaScript CISC 1600 Lecture 2.4 Introduction to JavaScript Topics: Javascript overview The DOM Variables and objects Selection and Repetition Functions A simple animation What is JavaScript? JavaScript is not Java

More information

(Refer Slide Time: 01:40)

(Refer Slide Time: 01:40) Internet Technology Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture No #25 Javascript Part I Today will be talking about a language

More information

JScript Reference. Contents

JScript Reference. Contents JScript Reference Contents Exploring the JScript Language JScript Example Altium Designer and Borland Delphi Run Time Libraries Server Processes JScript Source Files PRJSCR, JS and DFM files About JScript

More information

Client vs Server Scripting

Client vs Server Scripting Client vs Server Scripting PHP is a server side scripting method. Why might server side scripting not be a good idea? What is a solution? We could try having the user download scripts that run on their

More information

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives New Perspectives on Creating Web Pages with HTML Tutorial 9: Working with JavaScript Objects and Events 1 Tutorial Objectives Learn about form validation Study the object-based nature of the JavaScript

More information

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications JavaScript Started as a simple script in a Web page that is interpreted and run by the browser Supported by most modern browsers Allows dynamic update of a web page More generally, allows running an arbitrary

More information

JavaScript Introduction

JavaScript Introduction JavaScript Introduction JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Firefox, Chrome, Opera, and Safari. What is JavaScript?

More information

Coding in JavaScript functions

Coding in JavaScript functions Coding in JavaScript functions A function contains code that will be executed by an event or by a call to the function. You may call a function from anywhere within a page (or even from other pages if

More information

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

CISH-6510 Web Application Design and Development. Overview of JavaScript. Overview CISH-6510 Web Application Design and Development Overview of JavaScript Overview What is JavaScript? History Uses of JavaScript Location of Code Simple Alert Example Events Events Example Color Example

More information

Document Object Model (DOM)

Document Object Model (DOM) Document Object Model (DOM) HTML DOM The Document Object Model is a platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

CHAPTER 6 JAVASCRIPT PART 1

CHAPTER 6 JAVASCRIPT PART 1 CHAPTER 6 JAVASCRIPT PART 1 1 OVERVIEW OF JAVASCRIPT JavaScript is an implementation of the ECMAScript language standard and is typically used to enable programmatic access to computational objects within

More information

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

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) What is JavaScript? Web Development & Design Foundations with HTML5 Ninth Edition Chapter 14 A Brief Look at JavaScript and jquery Slides in this presentation contain hyperlinks. JAWS users should be able to get a list of

More information

JAVASCRIPT - OBJECTS OVERVIEW

JAVASCRIPT - OBJECTS OVERVIEW JAVASCRIPT - OBJECTS OVERVIEW http://www.tutorialspoint.com/javascript/javascript_objects.htm Copyright tutorialspoint.com JavaScript is an Object Oriented Programming OOP language. A programming language

More information

New Media Production Lecture 7 Javascript

New Media Production Lecture 7 Javascript 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

More information

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript CS 4640 Programming Languages for Web Applications JavaScript CS 4640 Programming Languages for Web Applications 1 How HTML, CSS, and JS Fit Together {css} javascript() Content layer The HTML gives the page structure and adds semantics Presentation

More information

Documents and computation. Introduction to JavaScript. JavaScript vs. Java Applet. Myths. JavaScript. Standard

Documents and computation. Introduction to JavaScript. JavaScript vs. Java Applet. Myths. JavaScript. Standard Introduction to Prof. Ing. Andrea Omicini II Facoltà di Ingegneria, Cesena Alma Mater Studiorum, Università di Bologna andrea.omicini@unibo.it Documents and computation HTML Language for the description

More information

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript CS 4640 Programming Languages for Web Applications JavaScript CS 4640 Programming Languages for Web Applications 1 How HTML, CSS, and JS Fit Together {css} javascript() Content layer The HTML gives the page structure and adds semantics Presentation

More information

Sprite an animation manipulation language Language Reference Manual

Sprite an animation manipulation language Language Reference Manual Sprite an animation manipulation language Language Reference Manual Team Leader Dave Smith Team Members Dan Benamy John Morales Monica Ranadive Table of Contents A. Introduction...3 B. Lexical Conventions...3

More information

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

JavaScript is described in detail in many books on the subject, and there is excellent tutorial material at JavaScript (last updated April 15, 2013: LSS) JavaScript is a scripting language, specifically for use on web pages. It runs within the browser (that is to say, it is a client- side scripting language),

More information

CE212 Web Application Programming Part 2

CE212 Web Application Programming Part 2 CE212 Web Application Programming Part 2 22/01/2018 CE212 Part 2 1 JavaScript Event-Handlers 1 JavaScript may be invoked to handle input events on HTML pages, e.g.

More information

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017 Loops! Loops! Loops! Lecture 5 COP 3014 Fall 2017 September 25, 2017 Repetition Statements Repetition statements are called loops, and are used to repeat the same code mulitple times in succession. The

More information

Programming language components

Programming language components Programming language components syntax: grammar rules for defining legal statements what's grammatically legal? how are things built up from smaller things? semantics: what things mean what do they compute?

More information

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017) COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017) RAMANA ISUKAPALLI RAMANA@CS.COLUMBIA.EDU 1 LECTURE-1 Course overview See http://www.cs.columbia.edu/~ramana Overview of HTML Formatting, headings,

More information

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

3Lesson 3: Functions, Methods and Events in JavaScript Objectives 3Lesson 3: Functions, Methods and Events in JavaScript Objectives By the end of this lesson, you will be able to: 1.3.1: Use methods as. 1.3.2: Define. 1.3.3: Use data type conversion methods. 1.3.4: Call.

More information

COMS 469: Interactive Media II

COMS 469: Interactive Media II COMS 469: Interactive Media II Agenda Review Data Types & Variables Decisions, Loops, and Functions Review gunkelweb.com/coms469 Review Basic Terminology Computer Languages Interpreted vs. Compiled Client

More information

CERTIFICATE IN WEB PROGRAMMING

CERTIFICATE IN WEB PROGRAMMING COURSE DURATION: 6 MONTHS CONTENTS : CERTIFICATE IN WEB PROGRAMMING 1. PROGRAMMING IN C and C++ Language 2. HTML/CSS and JavaScript 3. PHP and MySQL 4. Project on Development of Web Application 1. PROGRAMMING

More information

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

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript Program Structure function sqr(i) var result; // Otherwise result would be global. result = i * i; //

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

COMP519 Web Programming Lecture 14: JavaScript (Part 5) Handouts

COMP519 Web Programming Lecture 14: JavaScript (Part 5) Handouts COMP519 Web Programming Lecture 14: JavaScript (Part 5) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

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

What Is JavaScript? A scripting language based on an object-orientated programming philosophy. What Is JavaScript? A scripting language based on an object-orientated programming philosophy. Each object has certain attributes. Some are like adjectives: properties. For example, an object might have

More information

Working with JavaScript

Working with JavaScript Working with JavaScript Creating a Programmable Web Page for North Pole Novelties 1 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page 2 Objectives

More information

Then there are methods ; each method describes an action that can be done to (or with) the object.

Then there are methods ; each method describes an action that can be done to (or with) the object. When the browser loads a page, it stores it in an electronic form that programmers can then access through something known as an interface. The interface is a little like a predefined set of questions

More information

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

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world Visit us on the World Wide Web at: www.pearsoned.co.uk Pearson Education Limited 2014

More information

JavaScript. What s wrong with JavaScript?

JavaScript. What s wrong with JavaScript? JavaScript 1 What s wrong with JavaScript? A very powerful language, yet Often hated Browser inconsistencies Misunderstood Developers find it painful Lagging tool support Bad name for a language! Java

More information

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

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript Program Structure function sqr(i) var result; // Otherwise result would be global. result = i * i; //

More information

Web Programming/Scripting: JavaScript

Web Programming/Scripting: JavaScript CS 312 Internet Concepts Web Programming/Scripting: JavaScript Dr. Michele Weigle Department of Computer Science Old Dominion University mweigle@cs.odu.edu http://www.cs.odu.edu/~mweigle/cs312-f11/ 1 Outline!

More information

Basics of JavaScript. Last Week. Needs for Programming Capability. Browser as Development Platform. Using Client-side JavaScript. Origin of JavaScript

Basics of JavaScript. Last Week. Needs for Programming Capability. Browser as Development Platform. Using Client-side JavaScript. Origin of JavaScript Basics of JavaScript History of the Web XHTML CSS Last Week Nan Niu (nn@cs.toronto.edu) CSC309 -- Fall 2008 2 Needs for Programming Capability XHTML and CSS allows the browser to passively display static

More information

JavaScript by Vetri. Creating a Programmable Web Page

JavaScript by Vetri. Creating a Programmable Web Page XP JavaScript by Vetri Creating a Programmable Web Page 1 XP Tutorial Objectives o Understand basic JavaScript syntax o Create an embedded and external script o Work with variables and data o Work with

More information

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

COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

Scripting for Multimedia LECTURE 3: INTRODUCING JAVASCRIPT

Scripting for Multimedia LECTURE 3: INTRODUCING JAVASCRIPT Scripting for Multimedia LECTURE 3: INTRODUCING JAVASCRIPT Understanding Javascript Javascript is not related to Java but to ECMAScript It is widely used for client-side scripting on the web Javascript,

More information

JavaScript s role on the Web

JavaScript s role on the Web Chris Panayiotou JavaScript s role on the Web JavaScript Programming Language Developed by Netscape for use in Navigator Web Browsers Purpose make web pages (documents) more dynamic and interactive Change

More information

Web Development & Design Foundations with HTML5

Web Development & Design Foundations with HTML5 1 Web Development & Design Foundations with HTML5 CHAPTER 14 A BRIEF LOOK AT JAVASCRIPT Copyright Terry Felke-Morris 2 Learning Outcomes In this chapter, you will learn how to: Describe common uses of

More information

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 1 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) WHO

More information

JAVASCRIPT. sarojpandey.com.np/iroz. JavaScript

JAVASCRIPT. sarojpandey.com.np/iroz. JavaScript JAVASCRIPT 1 Introduction JAVASCRIPT is a compact, object-based scripting language for developing client Internet applications. was designed to add interactivity to HTML pages. is a scripting language

More information

SECTION II: LANGUAGE BASICS

SECTION II: LANGUAGE BASICS Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators

More information

Darshan Institute of Engineering & Technology for Diploma Studies Unit 2. 2 Working with JavaScript

Darshan Institute of Engineering & Technology for Diploma Studies Unit 2. 2 Working with JavaScript 2 Working with JavaScript JavaScript concept or What is JavaScript? JavaScript is the programming language of the Web. It is an object-oriented language that allows creation of interactive Web pages. It

More information

Introduction to DHTML

Introduction to DHTML Introduction to DHTML HTML is based on thinking of a web page like a printed page: a document that is rendered once and that is static once rendered. The idea behind Dynamic HTML (DHTML), however, is to

More information

COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts

COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information