Copyright ©2005  Department of Computer & Information Science Introducing DHTML & DOM: Form Validation.

Slides:



Advertisements
Similar presentations
The Web Wizards Guide To JavaScript Chapter 3 Working with Forms.
Advertisements

Copyright © 2003 Pearson Education, Inc. Slide 7-1 Created by Cheryl M. Hughes The Web Wizards Guide to XML by Cheryl M. Hughes.
Ch3: Introduction to HTML5 part 2 Dr. Abdullah Almutairi ISC 340 Fall 2014.
1 Topic 6 Processing Form Input. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction Form.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Web Database Programming Input Validation. User Input on the Web Web browser built-in mechanisms –HTML Forms HTTP POST method –Hyperlinks HTTP GET method.
Forms cs105. More Interactive web-pages So far what we have seen was to present the information. (Ex: tables. Lists,….). But it is not enough. We want.
JavaScript Forms Form Validation Cookies CGI Programs.
Tutorial 14 Working with Forms and Regular Expressions.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
CST JavaScript Validating Form Data with JavaScript.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
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
4-Sep-15 HTML Forms Mrs. Goins Web Design Class. Parts of a Web Form A Form is an area that can contain Form Control/Elements. Each piece of information.
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.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Client-Side Validation with Javascript by Daniel Yee.
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.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Copyright ©2005  Department of Computer & Information Science Introducing DHTML & DOM: JavaScript & Forms.
JavaScript II ECT 270 Robin Burke. Outline JavaScript review Processing Syntax Events and event handling Form validation.
JavaScript Part 1.
1 VU. 2 CS101 Introduction to Computing Lecture 15 More on Interactive Forms (Web Development Lecture 5)
© 2000 – All Rights Reserved - Page 1 Introduction to JavaScript Programming Part Two.
Introduction to JavaScript + More on Interactive Forms.
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.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 3.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Using Client-Side Scripts to Enhance Web Applications 1.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Introduction to HTML Part 3 Chapter 2. Learning Outcomes Identify how to design frames. Explain frames’ attributes. Describe the method on designing forms.
Microsoft FrontPage 2003 Illustrated Complete Creating a Form.
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
Introduction to JavaScript CS101 Introduction to Computing.
HTML Forms. Slide 2 Forms (Introduction) The purpose of input forms Organizing forms with a and Using different element types to get user input A brief.
The Web Wizard’s Guide To JavaScript Chapter 3 Working with Forms.
The Web Wizard’s Guide To JavaScript Chapter 3 Working with Forms.
Form Components and Elements
Copyright © Texas Education Agency, All rights reserved.1 Web Technologies Website Forms / Data Acquisition.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
HTML FORMS The TEXT Object Presented By: Ankit Gupta.
HTML FORMS Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan. 1.
FORM VALIDATION (Java Script ). Required Fields A required field in a form is a field that MUST have at least some content before the form will be processed.
ASSIGNMENT POINTS DUE DATE: Monday NOV 30 JAVASCRIPT, INPUT VALIDATION, REGEX See 2 nd slide for Form See 3 rd next slide for the required features.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Copyright (c) 2004 Prentice-Hall. All rights reserved. 1 Committed to Shaping the Next Generation of IT Experts. Project 6: Creating XHTML Forms Kelly.
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.
Beginning ASP.NET in C# and VB Chapter 9
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Ashima Wadhwa Java Script And Forms. Introduction Forms: –One of the most common Web page elements used with JavaScript –Typical forms you may encounter.
JavaScript, Sixth Edition
Chapter 5 Validating Form Data with JavaScript
Web Programming– UFCFB Lecture 17
Unit 27 - Web Server Scripting
The Web Wizard’s Guide To JavaScript
FORM OBJECT When creating an interactive web site for the Internet it is necessary to capture user input and process this input. Based on the result of.
Presentation transcript:

Copyright ©2005  Department of Computer & Information Science Introducing DHTML & DOM: Form Validation

Copyright ©2005  Department of Computer & Information Science Goals By the end of this lecture you should … Understand the differences between client-side & server-side validation.Understand the differences between client-side & server-side validation. Understand the differences between batch processing and real-time validation.Understand the differences between batch processing and real-time validation. continued …

Copyright ©2005  Department of Computer & Information Science Goals By the end of this lecture you should … Understand how to validate textboxes, passwords, select objects and radio buttons.Understand how to validate textboxes, passwords, select objects and radio buttons. Understand how to use Regular Expressions to look for specific patterns when validating data.Understand how to use Regular Expressions to look for specific patterns when validating data.

Copyright ©2005  Department of Computer & Information Science Introducing Form Validation Form validation is the process of checking the data that a user enters into form fields. We can write code to validate on the client-side or on the server-side.Form validation is the process of checking the data that a user enters into form fields. We can write code to validate on the client-side or on the server-side.

Copyright ©2005  Department of Computer & Information Science Client-Side Validation Client-side validation uses a scripting language, like JavaScript, to check the data a user enters into a form before the web browser sends that data to the server for processing.Client-side validation uses a scripting language, like JavaScript, to check the data a user enters into a form before the web browser sends that data to the server for processing. Client-side validation is usually very quick in responsiveness. However, it may not be entirely reliable, given that users may choose to disable JavaScript!Client-side validation is usually very quick in responsiveness. However, it may not be entirely reliable, given that users may choose to disable JavaScript!

Copyright ©2005  Department of Computer & Information Science Server-Side Validation Server-side validation is somewhat slower that client-side validation and relies on a program located on the server.Server-side validation is somewhat slower that client-side validation and relies on a program located on the server. While server-side validation may be slower, it is very reliable. The user can’t disable the server-side validation script.While server-side validation may be slower, it is very reliable. The user can’t disable the server-side validation script. Which type of validation should you use?Which type of validation should you use?

Copyright ©2005  Department of Computer & Information Science Validation Choices The best choice is to insure that your data is the most valid data that it can be – thus, use BOTH types of validation. Having validation on both sides, provides a fail-safe. Having an initial validation on the client-side results in a lighter load given to the server, but maintaining server-side validation insures that validation does happen (in case the user disabled JavaScript).The best choice is to insure that your data is the most valid data that it can be – thus, use BOTH types of validation. Having validation on both sides, provides a fail-safe. Having an initial validation on the client-side results in a lighter load given to the server, but maintaining server-side validation insures that validation does happen (in case the user disabled JavaScript).

Copyright ©2005  Department of Computer & Information Science Client-Side Validation Choices Batch Validation: Relies on the onSubmit event handler. Checks the entire form at once (well, almost -- depends on how you write your validation code).Batch Validation: Relies on the onSubmit event handler. Checks the entire form at once (well, almost -- depends on how you write your validation code). Real-Time Validation: Relies on the onChange / onBlur event handlers. Checks individual fields. Makes it easy to bypass correcting a problem.Real-Time Validation: Relies on the onChange / onBlur event handlers. Checks individual fields. Makes it easy to bypass correcting a problem.

Copyright ©2005  Department of Computer & Information Science Batch Validation & onSubmit We code the onSubmit event handler as an attribute of the form element.We code the onSubmit event handler as an attribute of the form element. Sending a Boolean value to onSubmit either allows a form to process ( true ) or prevents processing from happening ( false ).Sending a Boolean value to onSubmit either allows a form to process ( true ) or prevents processing from happening ( false ).

Copyright ©2005  Department of Computer & Information Science Calling a Batch Validation Function We use the reserved word return to get a Boolean value from the validation function and return that value to the event handler:We use the reserved word return to get a Boolean value from the validation function and return that value to the event handler:

Copyright ©2005  Department of Computer & Information Science Checking for Empty Textboxes We can write a validation function to check for empty textboxes by testing values against the textbox.value attribute.We can write a validation function to check for empty textboxes by testing values against the textbox.value attribute. We should check for the null value, the “” value and for empty spaces (using a regular expression).We should check for the null value, the “” value and for empty spaces (using a regular expression).

Copyright ©2005  Department of Computer & Information Science Open the file called formValidation_01.html

Copyright ©2005  Department of Computer & Information Science Checking for No Selections We can check against the selectedIndex attribute to see if a user made a choice form a selection menu. If the user failed to make a selection the value of selectedIndex == -1 (older browsers).We can check against the selectedIndex attribute to see if a user made a choice form a selection menu. If the user failed to make a selection the value of selectedIndex == -1 (older browsers). Newer browsers consider the first item selected automatically, if the user doesn’t make a choice ( selectedIndex == 0 ). Because of this, it’s a good idea to use the first option for instructions (like “Select One” ) and then check against the values -1 AND 0.Newer browsers consider the first item selected automatically, if the user doesn’t make a choice ( selectedIndex == 0 ). Because of this, it’s a good idea to use the first option for instructions (like “Select One” ) and then check against the values -1 AND 0.

Copyright ©2005  Department of Computer & Information Science Open the file called formValidation_02.html

Copyright ©2005  Department of Computer & Information Science Validating Passwords Like textboxes, we can validate passwords using password.value attribute.Like textboxes, we can validate passwords using password.value attribute. However, we might need to check for multiple situations, like:However, we might need to check for multiple situations, like: –The password matches the confirm field. –The password is of the correct length. –The password contains no illegal characters. –The password is comprised of a variety of different types of characters.

Copyright ©2005  Department of Computer & Information Science Open the file called formValidation_03.html

Copyright ©2005  Department of Computer & Information Science Validating Radio Buttons When can use the checked attribute to see if a user selected a radio button.When can use the checked attribute to see if a user selected a radio button. We can use a for loop to process through the radio button set, with a nested if to set a Boolean flag if the checked attribute is true.We can use a for loop to process through the radio button set, with a nested if to set a Boolean flag if the checked attribute is true.

Copyright ©2005  Department of Computer & Information Science Open the file called formValidation_04.html

Copyright ©2005  Department of Computer & Information Science Other Validation Examples Validating AddressesValidating Addresses Validating Zip CodesValidating Zip Codes Validating Phone NumbersValidating Phone Numbers

Copyright ©2005  Department of Computer & Information Science Open the file called formValidation_05.html

Copyright ©2005  Department of Computer & Information Science Open the file called formValidation_06.html

Copyright ©2005  Department of Computer & Information Science Open the file called formValidation_07.html

Copyright ©2005  Department of Computer & Information Science Summary Client-side validation ensures that data is sound before sending it to the server.Client-side validation ensures that data is sound before sending it to the server. It’s good practice to use both client-side and server-side validation.It’s good practice to use both client-side and server-side validation. We can use the value attribute to validate textboxes and passwords.We can use the value attribute to validate textboxes and passwords. continued …

Copyright ©2005  Department of Computer & Information Science Summary We can use for loops with if branches to check select objects and radio buttons.We can use for loops with if branches to check select objects and radio buttons. We can use regular expressions to match specific pattern values.We can use regular expressions to match specific pattern values.

Copyright ©2005  Department of Computer & Information Science Resources JavaScript Concepts & Techniques: Programming Interactive Web Sites by Tina Spain McDuffie (Franklin, Beedle & Associates, 2003) ISBN: JavaScript Concepts & Techniques: Programming Interactive Web Sites by Tina Spain McDuffie (Franklin, Beedle & Associates, 2003) ISBN: