Functions, Regular expressions and Events

Slides:



Advertisements
Similar presentations
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
Advertisements

The Web Warrior Guide to Web Design Technologies
Computer Science 103 Chapter 4 Advanced JavaScript.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
Tutorial 14 Working with Forms and Regular Expressions.
UNIT 6 JAVASCRIPT EVENT HANDLERS &WEB BROWSERS DETECTION.
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
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.
Tutorial 14 Working with Forms and Regular Expressions.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Introduction to JavaScript Gordon Tian
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
SERVER web page repository WEB PAGE instructions stores information and instructions BROWSER retrieves web page and follows instructions Server Web Server.
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
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.
05 – Java Script (1) Informatics Department Parahyangan Catholic University.
JavaScript, Fourth Edition
Event-Driven Programming Chapter Page Section: Section or division of an HTML page Generic block element Example: What's the difference between.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
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 Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
Understanding JavaScript and Coding Essentials Lesson 8.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
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.
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 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.
CIS 228 The Internet 12/6/11 Forms and Validation.
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.
Third lecture Event 27/2/2016 JavaScript Tutorial.
Java Script Date Object
JavaScript.
Build in Objects In JavaScript, almost "everything" is an object.
Week 3: Introduction to Javascript
Week 4: Introduction to Javascript
JavaScript is a programming language designed for Web pages.
© 2015, Mike Murach & Associates, Inc.
JavaScript.
Barb Ericson Georgia Institute of Technology May 2006
Introduction to Web programming
Web Development & Design Foundations with HTML5 7th Edition
JavaScript: Functions
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
CSCI 1720 JavaScript – Part 2 East Tennessee State University Department of Computing CSCI 1720 Intermediate Web Design.
Working with Forms and Regular Expressions
Your 1st Programming Assignment
Event Driven Programming & User Defined Functions
JavaScript MCS/BCS.
Web Design and Development
E-commerce Applications Development
Recognizing JavaScript Features
Events: Changed and Input
Code Topic 9 Standard JavaScript Events Laura Friedman
JavaScript Basics What is JavaScript?
JavaScript and Ajax (JavaScript Events)
Web Programming and Design
Week 5: Recap and Portfolio Site
Web Programming and Design
Web Programming and Design
Introduction to Web programming
Presentation transcript:

Functions, Regular expressions and Events JavaScript 4 Functions, Regular expressions and Events

Functions A JavaScript function is a block of code designed to perform a particular task. A JavaScript function is executed when "something" invokes it (calls it). A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses (). The code inside the function will execute when "something" invokes (calls) the function: When an event occurs (when a user clicks a button) When it is invoked (called) from JavaScript code Automatically (self invoked)

Function Declarations Functions are declared with the following syntax: function functionName(parameters) { code to be executed }

Function Expressions A JavaScript function can also be defined using an expression. A function expression can be stored in a variable: var x = function (a, b) {return a * b}; The function above is actually an anonymous function (a function without a name). Functions stored in variables, do not need function names. They are always invoked (called) using the variable name.

The Function() Constructor Functions can also be defined with a built-in JavaScript function constructor called Function(). var myFunction = new Function("a", "b", "return a * b"); var x = myFunction(4, 3);

Self Invoking Functions Function expressions can be made "self-invoking". A self-invoking expression is invoked (started) automatically, without being called. Function expressions will execute automatically if the expression is followed by (). You cannot self-invoke a function declaration. (function () { var x = "Hello!!"; // I will invoke myself })();

Functions are objects The typeof operator in JavaScript returns "function" for functions. But, JavaScript functions can best be described as objects. JavaScript functions have both properties and methods. function myFunction(a, b) { return arguments.length; }

Regular Expressions A regular expression is a sequence of characters that forms a search pattern. When you search for data in a text, you can use this search pattern to describe what you are searching for. A regular expression can be a single character, or a more complicated pattern. Regular expressions can be used to perform all types of text search and text replace operations. Syntax: /pattern/modifiers;

Regular Expression Modifiers i: Perform case-insensitive matching g: Perform a global match (find all matches rather than stopping after the first match) m: Perform multiline matching

Patterns Brackets are used to find a range of characters. Metacharacters are characters with a special meaning. \d: Find a digit \s: Find a whitespace character \b:Find a match at the beginning or at the end of a word Quantifiers define quantities. n+:Matches any string that contains at least one n n*: Matches any string that contains zero or more occurrences of n n?:Matches any string that contains zero or one occurrences of n

Events HTML events are "things" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can "react" on these events. Here are some examples of HTML events: An HTML web page has finished loading An HTML input field was changed An HTML button was clicked

Event Handlers Often, when events happen, you may want to do something. JavaScript lets you execute code when events are detected. HTML allows event handler attributes, with JavaScript code, to be added to HTML elements. <some-HTML-element some-event='some JavaScript'>

Common Events onchange: An HTML element has been changed onclick: The user clicks an HTML element onmouseover: The user moves the mouse over an HTML element onmouseout: The user moves the mouse away from an HTML element onkeydown: The user pushes a keyboard key onload: The browser has finished loading the page