Lecture 1 Term 2 9/1/12 1. Objects You normally use the “.” Operator to access the value of an object’s properties. The value on the left of the “.” should.

Slides:



Advertisements
Similar presentations
The Web Warrior Guide to Web Design Technologies
Advertisements

LECTURE 9 21/11/12 1. Comments in JavaScript // This is a single line JavaScript comment 2.
JavaScript (Part 2) CS 183 4/13/2010. JavaScript (Part 2) Will cover: ◦ For.. In ◦ Events ◦ Try.. Catch, Throw ◦ Objects.
L ECTURE 8 21/11/11. I NCREMENT O PERATORS OperatorCalledSample Expression Explanation ++preincrement++a Increment a by 1, then use the new value of a.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
JavaScript Bartosz Sakowicz. JavaScript - basics JavaScript is used in millions of Web pages to improve the design, validate forms, detect browsers, create.
Information Technology Center Hany Abdelwahab Computer Specialist.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Lesson15. JavaScript Objects Objects encapsulate data (properties) and behavior(methods); the properties and the methods of an object are tied together.
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.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
Introduction to JavaScript. JavaScript Facts A scripting language - not compiled but interpreted line by line at run-time. Platform independent. It is.
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT
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.
JavaScript Part 1.
JavaScript Part 1.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
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.
1 Introduction to Javascript Peter Atkinson. 2 Objectives To understand and use appropriately some of the basic elements of Javascript: –alert and prompt.
CC1003N Week 6 More CSS and Javascript.. Objectives: ● More CSS Examples ● Javascript – introduction ● Uses of Javascript ● Variables ● Comments ● Control.
Integrating JavaScript and HTML5 HTML5 & CSS 7 th Edition.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
Using Client-Side Scripts to Enhance Web Applications 1.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
JAVASCRIPT QUIZ BOWL By: Joseph Lindo. Quiz Bowl Mechanics  Group w/ 5 maximum members  Question is presented at the board  Prepare piece of papers.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
Introduction to Javascript. What HTML Can & Can Not Do HTML Can HTML Can Display text Display text Display images Display images Display even animated.
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
Intro to JavaScript. Some simple examples Examples from our webpage Examples from Andrews webpage Today’s Example.
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.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
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.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Introduction To JavaScript. Putting it Together (page 11) All javascript must go in-between the script tags. All javascript must go in-between the script.
COMP403 Web Design JAVA SCRİPTS Tolgay KARANFİLLER.
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming control structures, events, objects.
Jaana Holvikivi 1 Introduction to Javascript Jaana Holvikivi Metropolia.
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.
Chapter 12: Objects CIS 275—Web Application Development for Business I.
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".
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
JavaScript Event Handlers. Introduction An event handler executes a segment of a code based on certain events occurring within the application, such as.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
Event Handlers Events are asynchronous. When an event occurs, JavaScript can execute code in response to the user’s action. This response to the user-initiated.
Chapter 5: Intro to Scripting CIS 275—Web Application Development for Business I.
Chapter 4 Java Script - Part1. 2 Outlines Introduction to Java Script Variables, Operators and Functions Conditional statements JavaScript Objects Forms.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
Javascript Web Application Development M. Rehan Abbas Ch, UCP, Lahore.
COM621: Advanced Interactive Web Development Lecture 5 – JavaScript.
Third lecture Event 27/2/2016 JavaScript Tutorial.
Web Development & Design Foundations with HTML5
Web Development & Design Foundations with HTML5 7th Edition
JavaScript: Introduction to Scripting
JavaScript Intro.
JavaScript and Ajax (JavaScript Events)
Presentation transcript:

Lecture 1 Term 2 9/1/12 1

Objects You normally use the “.” Operator to access the value of an object’s properties. The value on the left of the “.” should be a reference to an object. The value to the right of the “.” should be the name of the method (property). This must be an identifier, not a string or expression. In the brackets following the method name is the argument to the method. 2

The Date object The Date object is used to work with dates and times. You create an instance of the Date object with the "new" keyword. To store the current date in a variable called "my_date": var my_date=new Date(); 3

Date () Returns today's date including date, month, and year. Note that the getMonth method returns 0 in January, 1 in February etc. So add 1 to the getMonth method to display the correct date. 4

Example Date var d = new Date(); document.write(d.getDate()); document.write("."); document.write(d.getMonth() + 1); document.write("."); document.write(d.getFullYear()); 5

Time() Returns the current local time including hour, minutes, and seconds. To return the GMT time use getUTCHours, getUTCMinutes 6

Example -Time var d = new Date(); document.write(d.getHours()); document.write("hours"); document.write(d.getMinutes()); document.write("minutes"); document.write(d.getSeconds()); document.write("seconds"); 7

Window Object alert("Hello World!") Opens alert box in window confirm("Press a button") Opens confirm box in window prompt("Please enter your name","") Opens prompt box in window window.open() Opens a new window May open multiple windows Location() Opens new URL in browser 8

Window Object location.reload() Refreshes a document window.status() Writes text in the window status bar. window.print() Prints the web page window.focus() tells the browser to send the window to the front of the screen. window.blur() tells the browser to send the window to the back of the screen. 9

function multipleWin() { window.open(" window.open(" window.status = "Happy New Year"; } 10

11 Math object Math.sqrt() Is called to calculate the square root of the number contained in the parenthese. Example var a =9; document.write(Math.sqrt(a));

12 Math Object Math.min(x,y) Smaller values of x and y var a = ; var b= ; document.write(Math.min(a,b)); Output= Math.max(x,y) Larger value of x and y var a = ; var b= ; document.write(Math.max(a,b)); Output= Math.round() Rounds to the nearest integer var a = ; document.write(Math.round(a)); Output=8

13 Events These are available event handlers that you can use: NB JavaScript is case sensitive: onClick() onSubmit() onMouseOver() onMouseOut() onFocus() onChange() onBlur() onLoad() onUnLoad()

14 Example 1-Mouseover <h1 onmouseover="style.color='blue'" onmouseout="style.color='green'"> Mouse over this text

15 Example 2 – onload() function mymessage() { alert("This message was triggered from the onload event"); }

16 Example 3 – onsubmit() var firstname; var x; function validate1() { x=document.myForm; firstname=x.myname.value; if (firstname =="") { alert("You must complete the name field"); x.myname.focus(); return false; } else { return true; } Enter your First Name:

17 JavaScript Functions A function is a set of statements You can reuse functions within the same script, or in other documents Functions can be defined both in the and in the section of a document. To assure that a function is read/loaded by the browser before it is called, it could be wise to put functions in the section To keep the browser from executing a script when the page loads, you can put your script into a function 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 the function is embedded in an external.js file)

18 How to Define a Function To create a function you define its name, any values ("arguments"), and some statements: function myfunction(argument1,argument2,etc) { some statements; }

19 How to Call a Function A function is not executed before it is called You can call a function containing arguments: function myfunction(argument1,argument2) { } or without arguments function myfunction() { }

20 Example Call Function function myfunction() { alert("HELLO IS6116"); }

Return Statement The return statement is used to specify the value that is returned from the function Functions that are going to return a value must use the return statement 21

22 var a=5; var b=4; var sum; function myFunction() { sum=a+b; return sum; } document.write(myFunction());

Form Validation Example var x; var firstname; var country1; var ; var phone1; var comment1; var at; var dot; function validate1() { x=document.myForm; dot=x.my .value.indexOf("."); firstname=x.myname.value; country1=x.country.value; =x.my .value; phone1=x.phone.value; comment1=x.comment.value; 23

if (firstname =="") { alert("You must complete the name field"); x.myname.focus(); return false; } else if(isNaN(firstname)== false) { alert("Please enter your name correctly"); x.myname.focus(); return false; } else if (country1 =="") { alert("You must complete the country field"); x.country.focus(); return false; } else if(isNaN(country1)== false) { alert("Please enter country correctly"); x.country.focus(); return false; } else if( == "") { alert("Please enter a vaild address"); x.my .focus(); return false; } 24

else if (at==-1) { alert("Please enter a vaild address "); x.my .focus(); return false; } else if (dot==-1) { alert("Please enter a vaild address "); x.my .focus(); return false; } else if(phone1=="") { alert("Please enter your phone number"); x.phone.focus(); return false; } else if(isNaN(phone1)==true) { alert("That phone number is not valid"); x.phone.focus(); return false; } else if(comment1=="") { alert("Please enter your comment!"); x.comment.focus(); return false; } return true; } 25

Enter your First Name: Enter your Country: Enter your Enter your Phone Number: Your Comment: 26