ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming control structures, events, objects.

Slides:



Advertisements
Similar presentations
Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
Advertisements

1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
JavaScript Objects - DOM CST 200 JavaScript. Objectives Introduce JavaScript objects Introduce Document Object Model Introduce window object Introduce.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
The Web Warrior Guide to Web Design Technologies
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.
Information Technology Center Hany Abdelwahab Computer Specialist.
CIS101 Introduction to Computing Week 10 Spring 2004.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
CIS101 Introduction to Computing Week 12 Spring 2004.
JavaScript Switch Statement. Switch JavaScript Switch Statement If you have a lot of conditions, you can use a switch statement instead of an if…elseif…
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Control Structures, Operators, and Functions.
1 Events Lect 8. 2 Event-driven Pages one popular feature of the Web is its interactive nature e.g., you click on buttons to make windows appear e.g.,
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.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
Generations of Programming Languages First generation  Machine Language Second Generation  Assembly Language Third Generation  Procedural language such.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
JavaScript Part 1.
JavaScript Part 1.
1 CLIENT-SIDE SCRIPTS. Objectives 2 Learn how to reference objects in HTML documents using the HTML DOM and dot syntax Learn how to create client-side.
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.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Objective Static vs. Dynamic Web pages. Variables. Assignments. JavaScript Hierarchy of Objects JavaScript Functions (prompt(“”,””) Document.write(“”)
Client Side Programming with JavaScript Why use client side programming? Web sides built on CGI programs can rapidly become overly complicated to maintain,
Using Client-Side Scripts to Enhance Web Applications 1.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
Intro to JavaScript Scripting language –ECMAScript compliant –Client side vs. server side Syntactic rules –White space –Statement end: ; optional –Comments:
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
JS Basics 1 Lecture JavaScript - Basics. JS Basics 2 What is JavaScript JavaScript is a “simple”, interpreted, programming language with elementary object-
Intro to JavaScript. Some simple examples Examples from our webpage Examples from Andrews webpage Today’s Example.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
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.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Dialog boxes in JavaScript Events in JavaScript – What are they – “Which events are there?” – “How do I register event handlers to an HTML element?” –
JavaScript, Fourth Edition
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
COMP403 Web Design JAVA SCRİPTS Tolgay KARANFİLLER.
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
IS2802 Introduction to Multimedia Applications for Business Lecture 3: JavaScript and Functions Rob Gleasure
Making dynamic pages with javascript Lecture 1. Java script java versus javascript Javascript is a scripting language that will allow you to add real.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
1 Javascript CS , Spring What is Javascript ? Browser scripting language  Dynamic page creation  Interactive  Embedded into HTML pages.
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 Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript 101 Lesson 6: Introduction to Functions.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
CHAPTER 10 JAVA SCRIPT.
JavaScript is a programming language designed for Web pages.
WEB APPLICATION PROGRAMMING
Week#2 Day#1 Java Script Course
CHAPTER 4 CLIENT SIDE SCRIPTING PART 2 OF 3
Introduction to Programming the WWW I
Event Driven Programming & User Defined Functions
Events Comp 205 Fall 2017.
T. Jumana Abu Shmais – AOU - Riyadh
JavaScript Basics What is JavaScript?
Presentation transcript:

ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming control structures, events, objects

ECA 225 Applied Interactive Programming Control Structures  Conditionals – allow scripts to make decisions  if  if/else  if/else/if  switch  Loops – executes same code a certain number of times  while  for  do/while  with

ECA 225 Applied Interactive Programming Conditionals: if statements  if if ( condition ) { statements if True } if (dogName == “Halle” ){ document.write( “You are a Golden Retriever” ); }

ECA 225 Applied Interactive Programming Conditionals: if statements cont …  if / else if ( condition ) { statements if True } else { statements if False } if(dogName = = “Halle” ){ document.write( “You are a Golden Retriever” ) ; } else{ document.write( “You are not my dog” ); }

ECA 225 Applied Interactive Programming Conditionals: if statements cont …  if / else if / else if ( condition ) { statements if first condition is True } else if (condition ) { statements if second condition is True } else { statements if False }

ECA 225 Applied Interactive Programming Conditionals: if statements cont …  if / else if / else if ( dogName = = “Halle” ){ document.write( “You are a Golden Retriever” ); } else if ( dogName = = “Marley” ){ document.write( “You are a Border Collie” ); } else if( dogName = = “Boo” ){ document.write( “You are a Monster” ); } else{ document.write( “You are not my dog” ); }

ECA 225 Applied Interactive Programming Conditional Conditional – takes place of if/else statement condition ? statements if True : statements if False age < 36 ? document.write( “You young pup!” ) : document.write( “You’re old!” );

ECA 225 Applied Interactive Programming Conditionals: switch switch( expression ) { case label1: statements; break; case label2: statements; break;... default: statements; }

ECA 225 Applied Interactive Programming Conditionals: switch cont … switch (dogName ) { case “Halle”: document.write( “ You are a Golden Retriever. ” ); break; case “Marley”: document.write( “ You are a Border Collie. ” ); break; case “Boo”: document.write( “ You are a Monster. ” ); break; default: document.write( “ You aren’t one of my dogs. ” ); } // end switch

ECA 225 Applied Interactive Programming Loops: while while( expression ) { statements } var x = 1; while( x <= 10 ){ document.write( x + “ ” ); x++; }

ECA 225 Applied Interactive Programming Loops: do…while do { statements } while ( condition ) var x = 1; do{ document.write( x + “ ” ); x++; } while( x <= 10 )

ECA 225 Applied Interactive Programming Loops: for for( initialize ; condition ; update ) { statements } for( x = 1; x <= 10; x++ ){ document.write( x + “ ” ); }

ECA 225 Applied Interactive Programming JavaScript Dialog Boxes  3 JavaScript methods to interact with user:  alert( )  used to alert the user with a message  takes one argument, the text which will appear in the alert box alert( “This is the message that will appear” );

ECA 225 Applied Interactive Programming JavaScript Dialog Boxes cont …  3 JavaScript methods to interact with user:  prompt( )  used to prompt the user for some information  takes two arguments, the prompt messaged, and a default response  returns the string typed in by the user var first_name = prompt( “Please enter your first name”, “” );

ECA 225 Applied Interactive Programming JavaScript Dialog Boxes cont …  3 JavaScript methods to interact with user:  confirm( )  asks the user to make a choice  takes one argument, the message which appears in the confirm box  returns a Boolean value var x = confirm( “Do you want to continue?” ); if( x ){ … }

ECA 225 Applied Interactive Programming Functions Functions are snippets of code that can be used over again in one script JavaScript has many built-in methods ( functions ) used to perform a specific task EG, Math.sqrt( ) takes a number and returns the square root // the following code calls the JavaScript method sqrt( ) var n = 49; document.write( Math.sqrt( n ) ); \\ prints the number 7

ECA 225 Applied Interactive Programming Functions cont … Programmers can define their own functions which perform specific tasks  declare using keyword function  follow by function name, using same rules for naming variables  parentheses after function name to hold arguments  curly brackets contain function statements  to call function, use the name followed by parentheses  return statement can be used to return a value  JavaScript has many built-in methods

ECA 225 Applied Interactive Programming Functions cont … simple functions // the following code calls the function alertUs( ) alertUs( ); function alertUs( ) { alert( “You have been alerted!” ); }

ECA 225 Applied Interactive Programming Functions cont … // the following code calls the function alertUs( ) var mess1 = “This is a message.”; alertUs( mess1 ); function alertUs( msg ) { alert( msg ); } functions taking one argument

ECA 225 Applied Interactive Programming Functions cont … var x = 3; var y = 6; var z = 11; document.write( “The answer is “ + mult( x, y ) ); // 18 document.write( “The answer is “ + mult( y, z ) ); // 66 // this function multiplies two numbers and returns the product function mult( a, b ) { c = a * b; return c; } // this is the end function mult( ) functions taking two arguments and returning a value

ECA 225 Applied Interactive Programming Events some kind of action performed by the user, such as clicking the mouse, rollover, submit a form Examples of events include:  click  mouseOver  mouseOut  submit

ECA 225 Applied Interactive Programming Events cont …  because JavaScript is client-side, user actions can be tracked  to capture the action, use commands called event handlers  an event handler is the name of the event with prefix on  using event handlers, we can associate a response with the user’s action

ECA 225 Applied Interactive Programming Events cont …  a function can be associated with an event handler function myTest( x ){ alert( x ); }

ECA 225 Applied Interactive Programming Events cont …  event handlers are case insensitive when used in HTML  event handlers are case sensitive when used in JavaScript  Other event handlers include  onMouseOver  onMouseOut  onClick  onSelect

ECA 225 Applied Interactive Programming Objects  everything in an HTML page is an individual object  each object has properties (characteristics that define the object) and methods (behaviors or actions) associated with it  some properties can be accessed and changed  most objects have properties and methods associated with them

ECA 225 Applied Interactive Programming Objects cont …  objects can contain other objects Window Document Image 1 Image 2 Form Link Text Box 1Text Box 2Text Area

ECA 225 Applied Interactive Programming Objects cont …  refer to objects by the name we give them Window Document img1 img2 myForm link1 firstNamelastNamecomments

ECA 225 Applied Interactive Programming Objects cont …  to refer to objects, properties, and methods use dot syntax  start at top-most object, usually window or document, including each object/property until we get to the one we want  EG, alert is a method of the window object  In general, we can omit the window object window.alert( “Hi “); ~~ or ~~ alert( “Hi” );

ECA 225 Applied Interactive Programming Objects cont …  to access what the user types into a form, we can use the value property function myTest( ){ var fName = document.myForm.first_name.value; alert( fName ); }

ECA 225 Applied Interactive Programming Objects cont …  using a function with the Form object function checkForm( ){ checkNames( fName = document.myForm.fName.value ); checkNames( lName = document.myForm.lName.value ); } function checkNames( nameInput ){ if( nameInput = = “” ){ document.write( “Please enter a value” ); return false; } First Name: Last Name:

ECA 225 Applied Interactive Programming Objects cont …  some of JavaScript’s objects  Array  Date  document  Form  Image  location  Math  String  window