INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.

Slides:



Advertisements
Similar presentations
Tutorial 6 Creating a Web Form
Advertisements

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.
CHAPTER 30 THE HTML 5 FORMS PROCESSING. LEARNING OBJECTIVES What the three form elements are How to use the HTML 5 tag to specify a list of words’ form.
Web Database Programming Input Validation. User Input on the Web Web browser built-in mechanisms –HTML Forms HTTP POST method –Hyperlinks HTTP GET method.
JavaScript Forms Form Validation Cookies CGI Programs.
Tutorial 14 Working with Forms and Regular Expressions.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Working with Forms in JavaScript (NON-audio version) © Dr. David C. Gibbs
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Chapter 10 Form Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
Introduction to JavaScript Form Verification - Fort Collins, CO Copyright © XTR Systems, LLC Verifying Submitted Form Data with JavaScript Instructor:
CSE 154 LECTURE 9: FORMS. Web data most interesting web pages revolve around data examples: Google, IMDB, Digg, Facebook, YouTube, Rotten Tomatoes can.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Lesson 8 Creating Forms with JavaScript
CST JavaScript Validating Form Data with JavaScript.
HTML 5 Tutorial Chapter 9 Form Attributes. New Form Attributes HTML5 has several new elements and attributes for forms. New form attributes : autocomplete.
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
INTRODUCTION TO WEB DEVELOPMENT AND HTML Lecture 07: Forms - Spring 2011.
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.
Copyright ©2005  Department of Computer & Information Science Introducing DHTML & DOM: Form Validation.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
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.
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.
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.
Project Four Forms Discuss form processing Describe the difference between client-side and server-side form processing Add a horizontal rule to a Web page.
Neal Stublen Improvements  New form elements  Assist with validation  Consistency across sites  Changes reduce the need for common.
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.
JavaScript Part 1.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 3.
Using Client-Side Scripts to Enhance Web Applications 1.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with 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.
Week 9 - Form Basics Key Concepts 1. 1.Describe common uses of forms on web pages 2.Create forms on web pages using the form, input, textarea, and select.
IS2802 Introduction to Multimedia Applications for Business Lecture 5: JavaScript, form validation and browser detection Rob Gleasure
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.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
Form Components and Elements
Copyright © Texas Education Agency, All rights reserved.1 Web Technologies Website Forms / Data Acquisition.
HTML5 Forms Forms are used to capture user input …
HTML Forms.
HTML 5 Form elements Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Radio Buttons. Input/Form/Radio Group Use the dialog to enter label and values for the radio buttons.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
1 Web Engineering Forms Lecture 05. FORMS Its how HTML does interactivity. There are quite new feature in HTML5. But the fundamental idea does not change.
CIS 228 The Internet 12/6/11 Forms and Validation.
Tutorial 6 Creating a Web Form
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,
Ashima Wadhwa Java Script And Forms. Introduction Forms: –One of the most common Web page elements used with JavaScript –Typical forms you may encounter.
Creating and Processing Web Forms
JavaScript, Sixth Edition
Chapter 5 Validating Form Data with JavaScript
In this session, you will learn to:
Web Development & Design Foundations with HTML5
Objectives Design a form Create a form Create text fields
Web Programming– UFCFB Lecture 17
The Web Wizard’s Guide To JavaScript
Presentation transcript:

INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE

Outline Client side validation – Using HTML5 features – Using JavaScript Next Class – DOM & Events 2

3 Client-Side Validation - Advantages Saves time and bandwidth. It's fast with immediate user feedback without having to wait for the page to load. You can safely display only one error at a time and focus on the wrong field, to help ensure that the user correctly fills in all the details as required. Still need server-side validation. Client and server-side validation complement each other, and as such, they really shouldn't be used independently.

4 Client-Side Validation - Approaches Display the errors one by one, focusing on the offending field. – Makes revising and successfully submitting the form much easier for the user Display all errors simultaneously, server- side validation style.

5 Client-Side Validation - Guidelines Presence or Absence Test – To determine whether the required fields left empty. Value Test – To determine if a field has a specific value or code. Range Test – To determine if a value entered is within a specific range (inclusive or exclusive)

6 Client-Side Validation - Guidelines Reasonableness Test – To determine if a value entered is reasonable based on other information supplied or information available to us. This test needs to be review periodically. Check Digit Test – To determine if for example, a credit card number or a Driver's license number is valid. Consistency Test MULTIPLE FIELD(s) – To determine if a value entered is consistent with other information entered.

Client-Side Validation - Client-Side Validation - Using HTML5  HTML5 provides several new input types & attributes for forms.  New Types: Color, date, , number, range – Note: these types are not universal. Some browsers do not support some of the new features 7 wk8 -> form_ex_3.html

Client-Side Validation - Client-Side Validation - Using HTML5  New Attributes:  required  required attribute – Specifies that an input field is required (must be filled out). – but spaces are acceptable. – For radio buttons, checkboxs and select-option, The required attribute is not supported in any of the major browsers.  pattern  pattern attribute – Specifies a regular expression to check the input value against. 8

Input Restrictions with HTML5  title  title attribute – Used to show validation rules  Minmaxmaxlength  Min, max, maxlength attributes – Specifies the minimum/maximum value for an input field 9 wk8-> form_ex_3.html

Client-side Validation with JavaScript One thing you’ve already known: – Validation on user’s input Two more things you need to know: – How to execute/call JavaScript code – How to access user’s input on the form

Where to put JavaScript Code? 1. In one or many JavaScript code chunks function func1() { /* Javascript code */ } Js.html

Where to put JavaScript Code? 2. In one or many JavaScript code chunks function func1() { /* JavaScript code */ } /* just some Javascript code, may be not in function */ Js.html

Where to put JavaScript Code? 3. As External file Syntax: In file ex.js: function message() { alert("This javaScript is in external file and was called with the onload event"); } Js.html

How Validation Function works onsubmit: <form method='post' name='form1' action = " onsubmit='return validateName()'> User clicks “submit” button, – trigger the validation function: validateName() – If validateName() returns true, the action will be taken – Otherwise, it returns to user, the form will not be submitted 14

15 Object Hierarchy

16 Example – Text (phone number) Text Box: – Rule: all digits function validateMyForm(frm1) { if (parseInt(frm1.phone.value) != frm1.phone.value) { alert('Please enter a phone number, numbers only'); frm1.phone.focus(); frm1.phone.select(); return false; } return true; } valid_phoneNumber.html valid_phoneNumber_pattern.html

17 Example – Text (name) Text Box: Rules: – at least one alphabetic letter (‘a’-’z’, ‘A’-’Z’) – Check no input var inputValue = document.form1.name.value; valid_text_name.html

18 Example – Datalist Datalist: Rules: – Must select one option from the data list var dl = document.ex.dept.value.trim(); valid_datalist.html

19 Example- TextArea TextArea: Rules: – presence – Not only blanks, – Not only New Line, – Not only Carriage if (document.form1.comments.value.length == 0) valid_textArea.html

20 Example- Radio Radio Button: Rule: – must select one valid_radio.html for (var i = 0; i < max; i++) { //if (document.form1.specialty[i].checked == true) if (document.form1.specialty[i].checked) { counter++; }

21 Example- CheckBox CheckBox: Rules: – At least check one – Check all of the above – Check none of the above – If checked one item, deselect the “check none of the above” – if (document.form1.system_type[i].checked) valid_checkbox.html

22 Example – Select Menu Selection (Select): – Property: selectedIndex sets or returns the index of the selected option in a drop-down list. The index starts at 0. If no option is selected, the selectedIndex property will return -1. If set selectedIndex property as -1, deselect all options. For multiple selections, return the index of the first option selected. selectFieldName.value: the selected option value Rule: – Require to select one item if (document.form1.plans.selectedIndex == -1) valid_select.html

23 Example- button, calculation, enable/disable Button: click a button, do calculation var total = items * Number(document.form1.costper.value) * 1.13; Enable/ Disable a field: document.form1.total.disabled = false; document.form1.total.value = ttotal.toFixed(2); document.form1.total.disabled = true; button_calculation.html

24 Example – “hidden” type This field will not show on the page It provides a means for servers to store state information with a form. change its value by JavaScript, not by user document.form1.jsEnabled.value = “Value 2"; hidden_type.html var hidValue = document.form1.jsEnabled.value; if (hidValue.toLowerCase() == “value1") { document.form1.jsEnabled.value = “value2"; /* Change hidden value */ }

Example – Hide / Show a field Name: function showHiddenField() { document.getElementById("hideText").disabled = false; document.getElementById("hideText").style.display = "block"; } function hideField() { var hideObj = document.getElementById("hideText"); hideObj.disabled = true; hideObj.style.display = "none"; } show_hide_field.html

26 Multiple Validation Rules function func1() { code1; } function func2() { code2; } ///////////////////////////// function validateAll() { if (func1() && func2()) { return true; } else { return false; } } // function validateAll() <form name="form1" method = "post“ action = " onsubmit="return validateAll();">

Validation using JavaScript Summary onsubmit: <form method='post' name='form1' action = " onsubmit='return validateName();'> Refer to the element: document.formname.elementname document.form1.name.value document.form1.specialty[i].checked if (document.form1.plans.selectedIndex == -1) 27

Validation using JavaScript Summary Refer to the element (cont’d): getElementById – using getElementById  document.getElementById("elementid") document.getElementById("elementid") this key word – using this key word  Using this key word in form element Using this key word in form element – using getElementsByName  document.getElementsByName("elementname") document.getElementsByName("elementname") returns a collection Validation function return true/false 28

Assignment #3 29

Next Class Events & DOM 30

Thank you!