JavaScript and Forms Kevin Harville.

Slides:



Advertisements
Similar presentations
5.1 JavaScript Execution Environment
Advertisements

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.
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.
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.
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.
Lesson 2 Event Handling. Object Event Handlers Most of the objects that make up the Document Object Model respond to asynchronous, user generated events.
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.
Lesson 8 Creating Forms with JavaScript
CST JavaScript Validating Form Data with JavaScript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript forms.
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.
Wednesday, March 5 th, 2014 Instructor: Craig Duckett Scripting Tables and Forms Murach - Chapter 17 Scripting Tables and Forms pp.
HTML Forms/Events (Instructor Lesson) The Event model HTML Forms Custom Events 1.
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 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Chapter 5 © 2003 by Addison-Wesley, Inc. 1 Chapter 5 JavaScript and HTML Documents.
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.
Forms Sangeetha Parthasarathy 02/05/2001. Introduction to Forms A form makes it possible to transform your web pages from text to graphics to interactive.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
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.
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.
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.
Chapter 19 Creating and Processing HTML Forms. How HTML Forms Transmit Data name1=value1&name2=value2...&nameN =valueN GET or POST GET, an HTTP GET request,
The Web Wizard’s Guide To JavaScript Chapter 3 Working with Forms.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
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.
HTML FORMS The TEXT Object Presented By: Ankit Gupta.
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.
JavaScript 1021 Nancy Leiby December 11, JavaScript 1022 JavaScript Notes Debugging JavaScript in Netscape … put ‘javascript:’ in the URL text box.
Chapter 14 The HTML Tag
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
Methods and Object Information. Some Document Methods.
Chapter 4 Java Script – Part2. 2 Location object Properties Properties href – whole path will be displayed. ex: window.location.href ( see example 11)
XHTML Forms.
HTML Again GUI Items Originally HTML 4 Copyright © Curt Hill.
5.1 JavaScript Execution Environment
Chapter 5 Validating Form Data with JavaScript
JavaScript and HTML Simple Event Handling 11-May-18.
In this session, you will learn to:
JavaScript - a Brief Introduction
Introduction to JavaScript Events
Forms Web Design Ms. Olifer.
(and available form fields)
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript and HTML Simple Event Handling 19-Sep-18.
JavaScript Events.
JavaScript and HTML Documents
New Perspectives on Creating Web Pages with HTML
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.
CHAPTER 7 JavaScripts & HTML Documents
Events: Changed and Input
JavaScript and Ajax (JavaScript Events)
JAVA SCRIPT OBJECTS & DOM
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

JavaScript and Forms Kevin Harville

Arrays of Objects We have discussed how JavaScript will automatically create arrays of similar objects. This holds true in several instances with forms. For example, if we have two forms in a page, JavaScript creates an array.

Form Array If I have two forms, myForm1, and myForm2, I can refer to them by name or as forms[0] and forms[1].

Form Properties Several exist, such as action, target, and method, which reflect those attribute values. We also have the length property. That indicates the number of form elements. EX: myTotal = forms[2].length

Form methods The form object has two methods, submit and reset. forms[1].submit forms[0].reset

Form Events In the form tag, we can use two event handlers: onSubmit and onReset. IMPORTANT. If a function for onSubmit or onReset returns 'true' the indicated action, submit or reset, takes place. If the function returns 'false' the indicated action does NOT take place. That lets us validate forms before they are submitted to the server!

Form Properties We can refer to form elements by name or by their array index. myVar = document.order.elements[0].value;

Text Field Properties name defaultValue value Often properties are read-only. That means you can not change them.

Text Area Properties Remember, textarea is different than input type of text. Otherwise, they are handled similarly in JavaScript.

Text Input and Area Methods focus() sets focus to the field blur() removes focus select() selects the text

Text Input and Area Events onFocus when a field gains focus onBlur when a field loses focus onChange when text changes and focus is lost onSelect when text is selected

Buttons The value property of any type of button is the text that appears on the button. onClick is our event handler

Check Box Properties name value the value returned if the box is checked defaultChecked default value checked true or false <input type="checkbox" name="check1" value="Yes" checked>

Check box method click() Changes the checkbox.

Radio Buttons Radio Buttons are different from Checkboxes. Only one should be chosen in any group. Our entire GROUP has a name and is an object, rather than dealing with each button seperately. Give each button in the group the same name. Give each button a different VALUE.

Properties The radio button group has the following properties: name length Each button in the group has the following properties: value defaultChecked checked document.form1.radio1[0].checked = true; //make all others false

Radio Button Methods/Events Method: click() Event: onClick

Drop Down Lists Drop down lists may be changed on the fly by JavaScript. select tags have the multiple attribute allowing multiple items from the list to be selected. option tags in our select tags have the selected attribute to indicate the default choice.

Select Properties name length options (array) selecteIndex (first one selected in list)

Option Properties The options array has a length property. Each option has the following properties: index array index value defaultSelected selected true or false name text text displayed

Select Methods / Events Method: blur() focus() Events: onBlur onFocus onChange

IMPORTANT Use two steps to get the values from select lists: myIndex = document.myform.mySelect.selectedIndex; myValue = document.myForm.mySelect.options[myIndex].value;

Form Validation Review a couple of validation scripts. This is one of the most common uses of JavaScript.