More Events and Validation CS380 1. Page/window events CS380 2.

Slides:



Advertisements
Similar presentations
Form Validation CS What is form validation?  validation: ensuring that form's values are correct  some types of validation:  preventing blank.
Advertisements

JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
Lesson 3 HTML Forms Handling. the Form object Tag : Properties: –action - action attribute of tag –elements[ ] - creeated from like named form elements.
JavaScript Forms Form Validation Cookies CGI Programs.
Tutorial 14 Working with Forms and Regular Expressions.
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
Form Validation CS What is form validation?  validation: ensuring that form's values are correct  some types of validation:  preventing blank.
CS 174: Web Programming February 26 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
. If the PHP server is an server or is aware of which server is the server, then one can write code that s information. –For example,
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
JavaScript Form Validation
Chapter 3 Using Validation Controls. What is a Validation Control? A control that validates the value in another control Renders as an HTML tag with an.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 9 Scott Marino.
Tutorial 14 Working with Forms and Regular Expressions.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Unobtrusive JavaScript
Modern JavaScript Develop And Design Instructor’s Notes Chapter 10 – Working with Forms Modern JavaScript Design And Develop Copyright © 2012 by Larry.
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.
Integrating JavaScript and HTML5 HTML5 & CSS 7 th Edition.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 3.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1 JavaScript in Context. Server-Side Programming.
CIS 451: Regular Expressions Dr. Ralph D. Westfall January, 2009.
Using Client-Side Scripts to Enhance Web Applications 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
1 Forms and Form elements CSD 340 McCoey. 2 Form Object Properties action Usually a call to a server elements encoding method post or get target Methods.
CS 174: Web Programming September 30 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Page Load © Copyright 2014, Fred McClurg All Rights Reserved.
Javascript’s RegExp. RegExp object Javascript has an Object which compiles Regular Expressions into a Finite State Machine The F.S.M. is internal, and.
CS346 Regular Expressions1 Pattern Matching Regular Expression.
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.
CS50 Week 9 Sam Green ’
LING 408/508: Programming for Linguists Lecture 14 October 19 th.
Unit 11 –Reglar Expressions Instructor: Brent Presley.
Functions.  Assignment #2 is now due on Wednesday, Nov 25 th  (No Quiz)  Go over the midterm  Backtrack and re-cover the question about tracing the.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
JavaScript Arrays, Functions, and Forms George Mason University.
Events CS The keyword this  all JavaScript code actually runs inside of an object  by default, code runs inside the global window object  all.
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.
An Introduction to Regular Expressions Specifying a Pattern that a String must meet.
Chapter 6 Murach's JavaScript and jQuery, C6© 2012, Mike Murach & Associates, Inc.Slide 1.
OVERVIEW OF CLIENT-SIDE SCRIPTING
CSE 154 LECTURE 10: MORE EVENTS. Problems with reading/changing styles Click Me HTML window.onload = function() { document.getElementById("clickme").onclick.
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.
Regular Expressions In Javascript cosc What Do They Do? Does pattern matching on text We use the term “string” to indicate the text that the regular.
Java Script Date Object
JavaScript.
Build in Objects In JavaScript, almost "everything" is an object.
Applied Component I Unit II Introduction of java-script
In this session, you will learn about:
SEEM4570 Tutorial 05: JavaScript as OOP
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript.
Web Programming– UFCFB Lecture 17
Working with Forms and Regular Expressions
CSE 154 Lecture 11: More Events.
Functions, Regular expressions and Events
Today’s Objectives Week 12 Announcements ASP.NET
JavaScript Basics Topics Overview Syntactic Characteristics
Lecture 11: Keyboard Events
CSE 337 Lecture 10: Events.
CSE 337 Lecture 10: Events.
JavaScript Basics Topics Review Important Methods Writing Functions
Lecture 11: Keyboard Events
Presentation transcript:

More Events and Validation CS380 1

Page/window events CS380 2

Page/window events CS380 3 // best way to attach event handlers on page load window.onload = function() {... }; document.observe("dom:loaded", function() { $("orderform").observe("submit", verify); }); JS

Form events CS380 4 window.observe("load", function() { $("orderform").observe("submit", verify); }); function verify(event) { if ($("zipcode").value.length < 5) { event.stop(); // cancel form submission unless } // zip code is 5 chars long } JS

Prototype and forms  gets parameter with given name from form with given id CS380 5 $("id")["name"] JS $F("id") JS  $F returns the value of a form control with the given id var name = $F("username"); if (name.length < 4) { $("username").clear(); $("login").disable(); } JS

Prototype and forms  other form control methods: CS380 6 activatecleardisableenable focusgetValuepresentselect

Client-side validation code  forms expose onsubmit and onreset events  to abort a form submission, call Prototype's Event.stop on the event 7 HTML window.onload = function() { $("exampleform").onsubmit = checkData; }; function checkData(event) { if ($("city").value == "" || $("state").value.length != 2) { Event.stop(event); alert("Error, invalid city/state."); // show error message } } JS

Regular expressions in JavaScript  string.match(regex)  if string fits the pattern, returns the matching text; else returns null  can be used as a Boolean truthy/falsey test: var name = $("name").value; if (name.match(/[a-z]+/)) {... }  an i can be placed after the regex for a case- insensitive match  name.match(/Xenia/i) will match “xenia", “XeNiA",... CS380 8

Replacing text with regular expressions  string.replace(regex, "text")  replaces the first occurrence of given pattern with the given text  var str = “Xenia Mountrouidou"; str.replace(/[a-z]/, "x") returns " Xxnia Mountrouidou"  returns the modified string as its result; must be stored str = str.replace(/[a-z]/, "x")  a g can be placed after the regex for a global match (replace all occurrences)  str.replace(/[a-z]/g, "x") returns “Xxxxx Mxxxxxxxxxxx" 9

Keyboard/text events 10

Key event objects CS rototype's key code constants

Key event objects CS  issue: if the event you attach your listener to doesn't have the focus, you won't hear the event  possible solution: attach key listener to entire page body, outer element, etc.