JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.

Slides:



Advertisements
Similar presentations
HTML Forms. collect information for passing to server- side processes built up from standard widgets –text-input, radio buttons, check boxes, option lists,
Advertisements

Tutorial 6 Creating a Web Form
The Web Warrior Guide to Web Design Technologies
Supplement Creating Forms. Objectives Show how forms are used How to create the Form element HTML elements used for creating input fields.
HTML and XHTML Controlling the Display Of Web Content.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
JavaScript Forms Form Validation Cookies CGI Programs.
Forms Review. 2 Using Forms tag  Contains the form elements on a web page  Container tag tag  Configures a variety of form elements including text.
Computer Science 103 Chapter 4 Advanced JavaScript.
USER INTERACTIONS: FORMS
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
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.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
CP476 Internet Computing JavaScript and HTML1 1.JavaScript Execution Environment The JavaScript Window object represents the window in which the browser.
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
MS3304: Week 4 PHP & HTML Forms. Overview HTML Forms elements refresher Sending data to a script via an HTML form –The post vs. get methods –Name value.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript forms.
JavaScript Form Validation
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.
CO1552 Web Application Development HTML Forms. Websites can be made more interactive by providing facilities for users to provide data To get user entered.
HTML Forms/Events (Instructor Lesson) The Event model HTML Forms Custom Events 1.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
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.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
JavaScript, Fourth Edition
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Copyright ©2005  Department of Computer & Information Science Introducing DHTML & DOM: JavaScript & Forms.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
Chapter 8 Cookies And Security JavaScript, Third Edition.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
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.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
7 Chapter Seven Client-side Scripts. 7 Chapter Objectives Create HTML forms Learn about client-side scripting languages Create a client-side script using.
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
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.
JavaScript Part 9 George Mason University June 23, 2010.
The Web Wizard’s Guide To JavaScript Chapter 3 Working with Forms.
Form Components and Elements
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.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
HTML Forms.
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.
Project 5: Customizing User Content Essentials for Design JavaScript Level Two Michael Brooks.
CIS 228 The Internet 12/6/11 Forms and Validation.
Lesson 5 Introduction to HTML Forms. Lesson 5 Forms A form is an area that can contain form elements. Form elements are elements that allow the user to.
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.
Chapter 5 Validating Form Data with JavaScript
In this session, you will learn to:
How to Write Web Forms By Mimi Opkins.
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.
Forms, cont’d.
JavaScript and Forms Kevin Harville.
Presentation transcript:

JavaScript Forms Form Validation Cookies

What JavaScript can do  Control document appearance and content  Control the browser  Interact with user  Interact with forms  Validate user input  Use cookies

HTML Forms  is a block-level element in the body of your HTML page  A form element can contain text input boxes, buttons, checkboxes, pull-down menus and images  Your document can have multiple form elements  A special button called Submit is used to send the form data to the server

JavaScript and Forms  With a server-side program, an HTML form needs a submit button  With JavaScript, you can react to events of individual input elements.  For some types of tasks, you may never need to submit at all.

Form Objects  An HTML form is represented in JavaScript by a Form object  document.forms[] is an array containing all the forms in the document  Each form object has an elements[] attribute which is an array of input elements  A form can be given a name attribute

Form Objects  Form methods include submit() and reset()  Submit and Reset buttons trigger onsubmit and onreset respectively  onsubmit and onreset handlers invoked just before corresponding method is called  If a handler returns false, the corresponding submit() or reset() method will not be invoked

Form Elements  Use the tag to create controls  type="input-type" needed to specify which type of control  name attribute needed to identify the element  There are special tags for, and

Form Elements and Events ObjectHTMLEvents Button onclick Checkbox onclick Radio onclick Select onchange Option - belongs to Select object Text onchange Password(input type="password">onchange Textarea onchange

Form Elements and Events ObjectHTMLEvents FileUpload onchange Hidden none Reset onclick Submit onclick

Names in Forms  If a form is to be submitted to a server side program, the name attribute of every element must be set  Within the javascript code, you can use the name of a form or form element instead of indexing into the corresponding array  For the form defined by  …  document.everything and document.forms[0] are equivalent ways to refer to the form

Properties of Form Elements  type - read only  form - read only reference to form element is part of  name - name that can be used to refer to the element  value - string sent to web server on submission  text entered by user for text and textarea  text displayed on a button  string set in HTML code for radio and chechbox

Event Handlers for Form Elements  onclick - triggered by mouse click  onchange - triggered by changing a value  onfocus - triggered when element receives focus  onblur - triggered when element loses focus

Validation  Check that all required fields have data e.value==null || e.value==""  Check the format of fields that contain information like addresses, URLs, phone numbers, …  Use the RegExp class to create patterns var pattern = /(\d{3}) \d{3}-\d{4}/  Use an alert to display error messages

Cookies  A cookie is a small amount of named data stored by the browser and associated with a particular web site  provide a way of saving state of a web page  last for current session by default  Server-side programs use cookies  JavaScript can manipulate cookie data

Cookie Attributes  name - each cookie has a name  value - value associated with the cookie  expires - cookies are transient unless this is set  path - web page(s) with which cookie is associated  domain - allows cookie to be available to different web servers  secure - Boolean attribute that specifies whether cookies must be transmitted over a secure (https) connection

Storing Cookies  Creating a transient cookie document.cookie = "version=" + escape( document.lastModified);  escape encodes characters that aren't allowed in the cookie  Storing other attributes with a cookie  Use semicolon to separate attribute=value pairs document.cookie = "version=" + escape(document.lastModified) + "; expires=" + nextYear.toGMTString();

Reading Cookies  document.cookie returns a string containing all the cookies for the document.  name=value pairs separated by semicolons  value does not include attributes