© 2007 D. J. ForemanJS-1 A Light Introduction for Non-programmers JavaScript for Beginners.

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

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
The Web Warrior Guide to Web Design Technologies
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
JavaScript (Part 2) CS 183 4/13/2010. JavaScript (Part 2) Will cover: ◦ For.. In ◦ Events ◦ Try.. Catch, Throw ◦ Objects.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
JavaScript Forms Form Validation Cookies CGI Programs.
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
Javascript Document Object Model. How to use JavaScript  JavaScript can be embedded into your html pages in a couple of ways  in elements in both and.
20-Jun-15 JavaScript and HTML Simple Event Handling.
Information Technology Center Hany Abdelwahab Computer Specialist.
Web Programming Material From Greenlaw/Hepp, In-line/On-line: Fundamentals of the Internet and the World Wide Web 1 Introduction The JavaScript Programming.
Javascript and the Web Whys and Hows of Javascript.
4.1 JavaScript Introduction
JS: DOM Form Form Object Form Object –The Form object represents an HTML form. –For each instance of a tag in an HTML document, a Form object is created.
HTML Forms/Events (Instructor Lesson) The Event model HTML Forms Custom Events 1.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
JavaScript - Document Object Model. Bhawna Mallick 2 Unit Plan What is DOM and its use? Hierarchy of DOM objects. Reflection of these objects in an HTML.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
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.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
JavaScript II ECT 270 Robin Burke. Outline JavaScript review Processing Syntax Events and event handling Form validation.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JavaScript Part 1.
Internet Mark-up Languages CO32036 Part Lecture: Elementary JavaScript.
JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client.
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Using Client-Side Scripts to Enhance Web Applications 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
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-
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
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.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
© 2007 D. J. Foreman (& U.H. St.Clair) JS-1 More JavaScript for Beginners Basic Concepts.
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.
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.
Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML.
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".
JavaScript II ECT 270 Robin Burke. Outline Functions Events and event handling Form validation.
JavaScript Event Handlers. Introduction An event handler executes a segment of a code based on certain events occurring within the application, such as.
Chapter 4 Java Script - Part1. 2 Outlines Introduction to Java Script Variables, Operators and Functions Conditional statements JavaScript Objects Forms.
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 and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
JavaScript and HTML Simple Event Handling 11-May-18.
JavaScript is a programming language designed for Web pages.
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript for Beginners
14 A Brief Look at JavaScript and jQuery.
JavaScript and HTML Simple Event Handling 19-Sep-18.
JavaScript Basics What is JavaScript?
JavaScript for Beginners
JavaScript for Beginners
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

© 2007 D. J. ForemanJS-1 A Light Introduction for Non-programmers JavaScript for Beginners

©2007 D. J. Foreman JS-2 JavaScript A scripting language (provides automation) Event driven Object oriented Platform Independent Secure

©2007 D. J. Foreman JS-3 So what’s the difference? JavaScript is NOT a true programming language JavaScript ONLY works in WebPages JavaScript ONLY works in a browser JavaScript is NOT like Java

©2007 D. J. Foreman JS-4 Some Uses for JavaScript Perform on-the-fly calculations Create user messages (alerts or dialogs) Read data from a table Customize web-pages at run-time Save time by eliminating server references Marquees Form manipulations

©2007 D. J. Foreman JS-5 How it works Browser loads the page Browser detects JavaScript Browser passes the script to the Interpreter Interpreter evaluates (performs) the script Script passes HTML back to Browser Browser displays page

©2007 D. J. Foreman JS-6 Variables, Statements & Control Structures

©2007 D. J. Foreman JS-7 Basics Variables: names that can hold data X, x, myval The var prefix is needed for objects and arrays and to "privatize" a name inside a function Expressions: perform computations X*Cuberoot(B) Statements: sentences that perform work X=x*y; // x and X are DIFFERENT document.write("aha ");

©2007 D. J. Foreman JS-8 Naming Conventions Each 'word' within the name of a variable usually gets capitalized: MySpecialName A constant (name for something that NEVER changes) is usually all caps: Math.PI, Math.LOG10E, MYINTRATE

©2007 D. J. Foreman JS-9 A strange statement Normal syntax: I=I+1; Shortened form: I++; ONLY for adding 1

©2007 D. J. Foreman JS-10 Adding comments Two kinds of JavaScript comments: // ignore remainder of this line /* ignore what's inside these markers */ VS One kind of HTML comment  !-- ignore what's inside these markers --  Note: tag ends with 2 DASHES before the ">"

© 2007 D. J. ForemanJS-11 Control statements Statements used to control the "flow" of execution within a JS program

©2007 D. J. Foreman JS-12 The if Statement Must be lowercase Tests a condition Controls flow of program Example: if (a==b) // note the TWO = signs {true part} else {false part}

©2007 D. J. Foreman JS-13 If (another example) if (a > b) document.write("See? 'A' was bigger"); else document.write('See? "A" was smaller or equal'); NOTE: single quotes inside the double-quoted strings or vice-versa

©2007 D. J. Foreman JS-14 The for Statement Must be lowercase Repeats a set of instructions Syntax: for (start ; test ; change) Example: for (i=1 ; i<10; i++) {instructions to be repeated go here}

©2007 D. J. Foreman JS-15 A short example X=window.prompt("number <10","0"); if (X>=10) document.write("number too big"); else for ( I=1 ; I<X ; I++) document.write(I+" ");

© 2007 D. J. ForemanJS-16 One big problem Some browsers may not accept JavaScript, so we have to hide it from them...

©2007 D. J. Foreman JS-17 Hiding JavaScript (from old browsers) <!-- hiding JavaScript These lines might confuse the browser, so the comment tags hide them. The and tags will be ignored (remember the rule about unknown tags?) //-- 

©2007 D. J. Foreman JS-18 Example 1: writing to the page <!-- hide the Javascript document.write (“I think we’re in trouble,Captain!"); // end of hide -->

©2007 D. J. Foreman JS-19 Example 2: A Prompt Window A PopUp Dialog <!-- hide from non-js browsers engrname = window.prompt("What's the engineer's name?",""); // pop-up text document.write("Thanks! Beam me up, " + engrname + "!! "); // note use of the "+" sign --> Display this line for every browser

©2007 D. J. Foreman JS-20 Events Connection between JS and the system Some pre-defined events: OnLoad / OnUnload OnClick / OnMouseOver OnFocus / OnBlur // see Prof. Hinton's website OnChange - lost focus and value changed OnSelect - text, textarea, password objects OnSubmit - with the form object

©2007 D. J. Foreman JS-21 Object Hierarchy Browser WindowHistoryLocation Document Links AnchorForms

©2007 D. J. Foreman JS-22 Some Document Properties alinkColor vlinkColor linkColor bgColor fgColor locationthe URL of this document titletext that appears in title-bar referrerURL of doc that linked to here

©2007 D. J. Foreman JS-23 Document Objects & Properties some examples document.title - contains the webpage title document.form (the form on the page) document.form.button1 (1st button on the form)

©2007 D. J. Foreman JS-24 More Document Objects Datemydate_object=new Date(); Mathx=Math.sqrt(xyz); framesframes[0] is the first frame stringsxyz="my data"; I=xyz.length; "mydata" is a string, as is the variable xyz objects have methods that perform work

©2007 D. J. Foreman JS-25 Examples of usage Can 'get' and ‘set’ properties of objects document.title="this is my webpage title"; X=document.title;

©2007 D. J. Foreman JS-26 Document Methods clear() close() open() write()

©2007 D. J. Foreman JS-27 Functions - program building blocks Function - user-defined sequence of code Placed between Defined within format: function function_name( ) {statements of the function go between the braces, and are ended with a semi-colon; }

©2007 D. J. Foreman JS-28 Invoking a Function – with onload <!-- function MYPOP() {xx=window.open("",xx,"menubar=yes, height=400, width=400"); xx.document.write(“Fire up the WarpDrive! ”); } // notice the difference from the prompt window //-- 

©2007 D. J. Foreman JS-29 Window.open Syntax Parameters URL, if any Name for new window Size attributes NOTEs: Quotes around WHOLE attribute string But no quotes around values in attributes

©2007 D. J. Foreman JS-30 Invoking a Function – from the body <!-- function MYPOP() {xx=window.open("",xx,"menubar=yes, height=400, width=400"); xx.document.write(“Fire up the WarpDrive! ”); } // notice the difference from window.prompt //--  <!-- MYPOP( ); -- 

©2007 D. J. Foreman JS-31 Objects within Forms Text fields and areas Password Checkbox Radio Select Button Reset Submit

©2007 D. J. Foreman JS-32 Limitations Interpreter is ‘hooked-into’ browser Cookies work differently on Mac vs Win Can’t access files (open, read, write)