TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 3.

Slides:



Advertisements
Similar presentations
MWD1001 Website Production Using JavaScript with Forms.
Advertisements

Tutorial 6 Creating a Web Form
Ch3: Introduction to HTML5 part 2 Dr. Abdullah Almutairi ISC 340 Fall 2014.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
JavaScript Forms Form Validation Cookies CGI Programs.
Computer Science 103 Chapter 4 Advanced JavaScript.
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.
Introduction to JavaScript Form Verification - Fort Collins, CO Copyright © XTR Systems, LLC Verifying Submitted Form Data with JavaScript Instructor:
. 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,
Lesson 8 Creating Forms with JavaScript
CST JavaScript Validating Form Data with JavaScript.
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
Copyright 2007, Information Builders. Slide 1 Maintain & JavaScript: Two Great Tools that Work Great Together Mark Derwin and Mark Rawls Information Builders.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
Jquery IS JQuery Jquery Example of mouseover event that shows a submenu when menu selected: $(‘#menu’).mouseover(function() { $(‘#submenu’).show();
Copyright ©2005  Department of Computer & Information Science Introducing DHTML & DOM: Form Validation.
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.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Faculty of Sciences and Social Sciences HOPE JavaScript Validation Regular Expression Stewart Blakeway FML
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
JavaScript Part 1.
JavaScript Lecture 6 Rachel A Ober
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
JavaScript – part II. The if Statement if (condition) { block of code to be executed if the condition is true }
Intro to JavaScript. Use the tag to tell the browser you are writing JavaScript.
Using Client-Side Scripts to Enhance Web Applications 1.
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.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
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.
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.
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.
Unit 10 – JavaScript Validation Instructor: Brent Presley.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
Validation using Regular Expressions. Regular Expression Instead of asking if user input has some particular value, sometimes you want to know if it follows.
Unit 2 — The Exciting World of JavaScript Lesson 7 — Creating Forms with JavaScript.
5 th and 4 th ed: some from chapters 9, 12, 13 SY306 Web and Databases for Cyber Operations Slide Set #8: Dynamic HTML.
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.
HTML 5 Form elements Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Form Validation. Create a form for the user to enter the data seen blow.
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.
JavaScript Event Handlers. Introduction An event handler executes a segment of a code based on certain events occurring within the application, such as.
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 Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Popup Boxes.
CIS 228 The Internet 12/6/11 Forms and Validation.
Strings Robin Burke IT 130. Outline Objects Strings methods properties Basic methods Form validation.
Tutorial 6 Creating a Web Form
JavaScript, Third Edition 1 SELECTION LIST Demo. JavaScript, Third Edition 2 Description This web page will edit the slection to ensure an option was.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
Third lecture Event 27/2/2016 JavaScript Tutorial.
JavaScript, Sixth Edition
Build in Objects In JavaScript, almost "everything" is an object.
Web Programming– UFCFB Lecture 17
Working with Forms and Regular Expressions
Conditionally Confirming a Submit
Today’s Objectives Week 12 Announcements ASP.NET
Validation using Regular Expressions
Presentation transcript:

TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 3

Objectives  Why using JavaScript for Form Validation  How to check for non-empty fields  How to check for all numbers  How to check for all letters  How to check for numbers and letters  How to restrict the length  How to check a selection has been made  How to validate

Why Using JavaScript for Form Validation?  Avoid the headaches of incomplete form submitted data.  Idea: Using JavaScript form validation  to provide a method to check the user entered information before they can even submit it.  To display useful alerts to inform the user what information they have entered incorrectly. how they can fix it.

How to check for non-empty fields Step 1: JavaScript Code (fill the blank) // If the length of the element's string is 0 then display helper message function notEmpty(elem, helperMsg){ if(elem.value.length == 0){ alert(helperMsg); elem.focus(); //set the focus to this input return false; } return true; } Step 2: Add onclick attribute to the field

Practice: check for non-empty fields  In-Class Example

How to Check for All Numbers Step 1: JavaScript Code // If the element's string matches the regular expression it is all numbers function isNumeric(elem, helperMsg){ var numericExpression = /^[0-9]+$/; if(elem.value.match(numericExpression)){ return true; }else{ alert(helperMsg); elem.focus(); return false; }

How to Check for All Numbers  Step 2: Add onclick attribute to the field

Practice: check for all numbers  In-Class Example

How to Check for All Letters  Step 1: JavaScript Code // If the element's string matches the regular expression it is all letters function isAlphabet(elem, helperMsg){ var alphaExp = /^[a-zA-Z]+$/; if(elem.value.match(alphaExp)){ return true; } else{ alert(helperMsg); elem.focus(); return false; }  Step 2: Add onclick attribute to the field

Practice: Check for all Letters  In-Class Example

How to Check for Numbers and Letters  Step 1: JavaScript Code // If the element's string matches the regular expression it is numbers and letters function isAlphanumeric(elem, helperMsg){ var alphaExp = /^[a-zA-Z0-9\s-]+$/; if(elem.value.match(alphaExp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; }  Step 2: Add onclick attribute to the field

Practice: Check for Numbers and Letters  In-Class Example

How to Restrict the Length  Step 1: JavaScript Code function lengthRestriction(elem, min, max){ var uInput = elem.value; if(uInput.length >= min && uInput.length <= max){ return true; }else{ alert("Please enter between " +min+ " and " +max+ " characters"); elem.focus(); return false;} }  Step 2: Add onclick attribute to the field

Practice: Restrict the Length  In-Class Example

How to Check a Selection has been Made  Step 1: JavaScript Code function madeSelection(elem, helperMsg){ if(elem.value == "Please Choose"){ alert(helperMsg); elem.focus(); return false; }else{ return true; }  Step 2: Add onclick attribute to the field

Practice: Check Selection Made  In-Class Example

How to Validate  Step 1: JavaScript Code function Validator(elem, helperMsg){ var Exp = 9]{2,4}$/; if(elem.value.match( Exp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; }}  Step 2: Add onclick attribute to the field

Practice: Validate  In-Class Example

Validating a Form all at Once: Bringing All Together  JavaScript Code:  Each required fields should be filled (or non-empty).  Form Code:  Each form has a JavaScript event called onSubmit that is triggered when its submit button is clicked.  If this event returns 0 or false then a form cannot be submitted  if the event returns 1 or true it will always be submitted.

Practice: Complete Validation a Form  In Class Example