Netprog: JavaScript1 JavaScript Client-side dynamic documents.

Slides:



Advertisements
Similar presentations
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Advertisements

JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
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
EIW: Javascript the Language1 The JavaScript Language.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
20-Jun-15 JavaScript and HTML Simple Event Handling.
Computer Science 103 Chapter 4 Advanced JavaScript.
Lecture 16 JavaScript (SMTP, POP) CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Introduction to scripting
1 Prototype-basedPrototype-based scripting languagescripting language.
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
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Scripting Languages.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
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.
Chapter 3 : Processing on the Front End JavaScript Technically its name is ECMA-262, which refers to the international standard which defines it. The standard.
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.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
What is Java Script? An extension to HTML. An extension to HTML. Allows authors to incorporate some functionality in their web pages. (without using CGI.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
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.
1 Lecture #6 Dynamic Web Documents HAIT Summer 2005 Shimrit Tzur-David.
An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition.
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,
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.
1 JavaScript
JavaScript Syntax, how to use it in a HTML document
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.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
Scripting and Interactivity 이병희
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
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.
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming control structures, events, objects.
Making dynamic pages with javascript Lecture 1. Java script java versus javascript Javascript is a scripting language that will allow you to add real.
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".
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript Tutorial First lecture 19/2/2016. Javascript is a dynamic computer programming language. It is lightweight and most commonly used as a part.
CGS 3066: Web Programming and Design Spring 2017
Java Script Introduction. Java Script Introduction.
JavaScript and HTML Simple Event Handling 11-May-18.
“Under the hood”: Angry Birds Maze
JavaScript is a programming language designed for Web pages.
14 A Brief Look at JavaScript and jQuery.
JavaScript and HTML Simple Event Handling 19-Sep-18.
JavaScript Basics What is JavaScript?
JavaScript is a scripting language designed for Web pages by Netscape.
CNIT 133 Interactive Web Pags – JavaScript and AJAX
Web Programming and Design
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

Netprog: JavaScript1 JavaScript Client-side dynamic documents

Netprog: JavaScript2 Smart Browsers Most browsers support a tag that is used to include executable content in an HTML document. There are a number of scripting languages that are supported

Netprog: JavaScript3 Client-Side Script Languages Netscape and othersNetscape and others –JavaScript Internet ExplorerInternet Explorer –Jscript (MS name for JavaScript) –VBScript –PerlScript

Netprog: JavaScript4 JavaScript Capabilities Add content to a web page dynamically. Alter a web page in response to user actions. React to user events. Interact with frames. Manipulate HTTP cookies

Netprog: JavaScript5 JavaScript is not Java JavaScript is a very simple scripting language.JavaScript is a very simple scripting language. Syntax is similar to a subset of Java.Syntax is similar to a subset of Java. Interpreted language.Interpreted language. Uses objects, but doesn't really support the creation of new object types*Uses objects, but doesn't really support the creation of new object types* *It almost does, but it's cumbersome.

Netprog: JavaScript6 Language Elements VariablesVariables LiteralsLiterals OperatorsOperators Control StructuresControl Structures ObjectsObjects

Netprog: JavaScript7 JavaScript Variables Untyped!Untyped! Can be declared with var keyword:Can be declared with var keyword: var foo; Can be created automatically by assigning a value:Can be created automatically by assigning a value: foo=1; blah="Hi Dave";

Netprog: JavaScript8 Variables (cont.) Using var to declare a variable results in a local variable (inside a function).Using var to declare a variable results in a local variable (inside a function). If you don't use var – the variable is a global variable.If you don't use var – the variable is a global variable.

Netprog: JavaScript9 Literals The typical bunch:The typical bunch: –Numbers –Strings "Hello Dave" –Boolean: true false –Arrays: [1,"Hi Dave",17.234] Arrays can hold anything!

Netprog: JavaScript10 Operators Arithmetic, comparison, assignment, bitwise, boolean (pretty much just like C).Arithmetic, comparison, assignment, bitwise, boolean (pretty much just like C). + - * / % == != > < && || ! & | >

Netprog: JavaScript11 Control Structures Again – pretty much just like C:Again – pretty much just like C: if if-else ?: switch for while do-while And a few not in CAnd a few not in C for (var in object) with (object)

Netprog: JavaScript12 Objects Objects have attributes and methods.Objects have attributes and methods. Many pre-defined objects and object types.Many pre-defined objects and object types. Using objects follows the syntax of C++/Java:Using objects follows the syntax of C++/Java: objectname.attributename objectname.methodname()

Netprog: JavaScript13 Array Objects Arrays are supported as objects.Arrays are supported as objects. Attribute lengthAttribute length Methods include:Methods include: concat join pop push reverse sort

Netprog: JavaScript14 Array example code var a = [8,7,6,5]; for (i=0;i<a.length;i++) a[i] += 2; b = a.reverse();

Netprog: JavaScript15 Many other pre-defined object types String : manipulation methods Math : trig, log, random numbers Date : date conversions RegExp : regular expressions Number : limits, conversion to string

Netprog: JavaScript16 Predefined Objects JavaScript also includes some objects that are automatically created for you (always available). –document –navigator –screen –window

Netprog: JavaScript17 The document object Many attributes of the current document are available via the document object: TitleReferrer URLImages FormsLinks Colors

Netprog: JavaScript18 document methods document.write() like a print statement – the output goes into the HTML document. document.write("My title is" + document.title); string concatenation!

Netprog: JavaScript19 JavaScript Example JavaScript is Javalicious I am a web page and here is my name: document.write(document.title); JavaScript is Javalicious I am a web page and here is my name: document.write(document.title);

Netprog: JavaScript20 JavaScript and HTML Comments <SCRIPT><!-- document.write("Hi Dave"); document.bgColor="BLUE";--></SCRIPT> HTML comment

Netprog: JavaScript21 JavaScript Functions The keyword function used to define a function (subroutine):The keyword function used to define a function (subroutine): function add(x,y) { return(x+y);}

Netprog: JavaScript22 JavaScript Events JavaScript supports an event handling system.JavaScript supports an event handling system. –You can tell the browser to execute javascript commands when some event occurs. –Sometimes the resulting value of the command determines the browser action.

Netprog: JavaScript23 Simple Event Example Hello - I am a very small page! savewidth = window.innerWidth; saveheight = window.innerHeight; function restore() { window.innerWidth=savewidth; window.innerHeight=saveheight; } // Change the window size to be small window.innerWidth=300; window.innerHeight=50; document.bgColor='cyan'; Hello - I am a very small page! savewidth = window.innerWidth; saveheight = window.innerHeight; function restore() { window.innerWidth=savewidth; window.innerHeight=saveheight; } // Change the window size to be small window.innerWidth=300; window.innerHeight=50; document.bgColor='cyan';

Netprog: JavaScript24 Buttons You can associate buttons with JavaScript events (buttons in HTML forms)You can associate buttons with JavaScript events (buttons in HTML forms) <INPUT TYPE=BUTTON VALUE="Don't Press Me" onClick="alert('now you are in trouble!')“ > <INPUT TYPE=BUTTON VALUE="Don't Press Me" onClick="alert('now you are in trouble!')“ >

Netprog: JavaScript25 Some Events (a small sample) onUnLoad onLoad onClick onMouseUp onMouseDown onDblClick onMouseOver Window events Button events Link events

Netprog: JavaScript26 Document Object Model Naming hierarchy used to access individual elements of a HTML document. Netscape D.O.M. is a little different than IE D.O.M. (D.A.M.)!!!* Easy to use if you name all entities: –Forms, fields, images, etc. Things are getting better all the time – there are standard DOMs defined by The W3C

Netprog: JavaScript27 DOM example <FORM ID=myform ACTION=… Please Enter Your Age: And your weight: From javascript you can get at the age input field as: document.myform.age.value

Netprog: JavaScript28 Form Field Validation You can have JavaScript code that makes sure the user enters valid information. When the submit button is pressed the script checks the values of all necessary fields: –You can prevent the request from happening.

Netprog: JavaScript29 Checking Fields function checkform() { if (document.myform.age.value == "") { alert("You need to specify an age"); return(false); } else { return(true); } function checkform() { if (document.myform.age.value == "") { alert("You need to specify an age"); return(false); } else { return(true); } Needs to return true or false!

Netprog: JavaScript30 The Form <FORM METHOD=GET ACTION=foo.cgi NAME=myform onSubmit="return(checkform())"> AGE: <FORM METHOD=GET ACTION=foo.cgi NAME=myform onSubmit="return(checkform())"> AGE: Needed to prevent the browser from submitting!

Netprog: JavaScript31 Complete Form Example Check the CGI example named "JavaScript" for a complete example: –Student grade database with form field validation in the form.

Netprog: JavaScript32 Important Note about Form Validation!!! It's a good idea to make sure the user fills out the form before submitting. Users can bypass your form – they can create requests manually (or their own forms). Your CGI programs cannot rely (soley) on Client-Side JavaScript to validate form fields!

Netprog: JavaScript33 Lots of JavaScript There are many javascript examples available via the course home page: "Stupid JavaScript Tricks“ Got one of your own? Send it to Dave!