Copyright ©2005  Department of Computer & Information Science Introducing DHTML & DOM: JavaScript & Forms.

Slides:



Advertisements
Similar presentations
23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
Advertisements

24-Aug-14 HTML Forms. 2 What are forms? is just another kind of HTML tag HTML forms are used to create (rather primitive) GUIs on Web pages Usually the.
Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
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.
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.
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Chapter 10 Form Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
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.
Chapter 9 Working with Forms. Principles of Web Design 2nd Ed. Chapter 9 2 Principles of Web Design Chapter 9 Objectives Understand how forms work Understand.
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.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript forms.
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.
HTML Forms/Events (Instructor Lesson) The Event model HTML Forms Custom Events 1.
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.
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.
JavaScript II ECT 270 Robin Burke. Outline JavaScript review Processing Syntax Events and event handling Form validation.
© 2000 – All Rights Reserved - Page 1 Introduction to JavaScript Programming Part Two.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
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.
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
Week 12 Working with Forms Objectives Understand how forms work Understand form syntax Create input objects Build forms within tables Build and.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
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.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
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,
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
Form Components and Elements
Web Technologies Lecture 3 Web forms. HTML5 forms A component of a webpage that has form controls – Text fields – Buttons – Checkboxes – Range controls.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Copyright © Texas Education Agency, All rights reserved.1 Web Technologies Website Forms / Data Acquisition.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
HTML FORMS The TEXT Object Presented By: Ankit Gupta.
HTML FORMS Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan. 1.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Creating Forms on a Web Page. 2 Introduction  Forms allow Web developers to collect visitor feedback  Forms create an environment that invites people.
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.
1 HTML forms (cont.)
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
CIS 228 The Internet 12/6/11 Forms and Validation.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
Chapter 5 Validating Form Data with JavaScript
In this session, you will learn to:
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.
JavaScript and Forms Kevin Harville.
Presentation transcript:

Copyright ©2005  Department of Computer & Information Science Introducing DHTML & DOM: JavaScript & Forms

Copyright ©2005  Department of Computer & Information Science Goals By the end of this lecture you should … Understand the differences between methods of posting form data.Understand the differences between methods of posting form data. Understand how to program using different form event handlers.Understand how to program using different form event handlers. Understand how to use JavaScript to read the values from various form objects.Understand how to use JavaScript to read the values from various form objects.

Copyright ©2005  Department of Computer & Information Science The form Object In order to access form elements, we need to create a form object using the XHTML container.In order to access form elements, we need to create a form object using the XHTML container. A valid container must include a value for the name attribute and also assigns values for the method and action attributes.A valid container must include a value for the name attribute and also assigns values for the method and action attributes.

Copyright ©2005  Department of Computer & Information Science form Element Attributes name – The name attribute provides a unique identifier for the form and provides for access by scripts.name – The name attribute provides a unique identifier for the form and provides for access by scripts. action – The action attribute specifies what to do when the user clicks to submit the form.action – The action attribute specifies what to do when the user clicks to submit the form. method – The method attribute specifies how the web browser should send form values to the form processing script. Valid values include either get or post.method – The method attribute specifies how the web browser should send form values to the form processing script. Valid values include either get or post.

Copyright ©2005  Department of Computer & Information Science form Sample Form objects go here. </form>

Copyright ©2005  Department of Computer & Information Science Referencing the form Object To reference the form object in your JavaScripts, use a path to the form name: window.document.formNameTo reference the form object in your JavaScripts, use a path to the form name: window.document.formName Alternatively, you can reference the form use the window.forms array: window.document.forms[index]Alternatively, you can reference the form use the window.forms array: window.document.forms[index]

Copyright ©2005  Department of Computer & Information Science form Event Handlers onSubmit – Allows us to run JavaScript commands before the browser sends form values for processing; interrupts that request if onSubmit receives a false value.onSubmit – Allows us to run JavaScript commands before the browser sends form values for processing; interrupts that request if onSubmit receives a false value. onReset – Allows us to run JavaScript commands before the form resets to default values; interrupts the reset if onReset receives a false value.onReset – Allows us to run JavaScript commands before the form resets to default values; interrupts the reset if onReset receives a false value.

Copyright ©2005  Department of Computer & Information Science Handling Textboxes To read or set the value of a textbox, use a path to the textbox’s value attribute: window.document.formName. textboxName.valueTo read or set the value of a textbox, use a path to the textbox’s value attribute: window.document.formName. textboxName.value

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

Copyright ©2005  Department of Computer & Information Science Form Component Event Handlers onFocus – When a cursor moves to a form component.onFocus – When a cursor moves to a form component. onClick – When the user clicks inside or on a form component.onClick – When the user clicks inside or on a form component. onBlur – When the user moves the cursor from a form component.onBlur – When the user moves the cursor from a form component. onChange – When the user changes the value/state of a form component.onChange – When the user changes the value/state of a form component.

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

Copyright ©2005  Department of Computer & Information Science Preventing Textbox Manipulation Sometimes, you might want to use a textbox for output instead of input (for instance, for the results of calculations). To prevent users from manipulating textbox values, use the blur() method to prevent a cursor from setting focus: onFocus = “this.blur()”;Sometimes, you might want to use a textbox for output instead of input (for instance, for the results of calculations). To prevent users from manipulating textbox values, use the blur() method to prevent a cursor from setting focus: onFocus = “this.blur()”;

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

Copyright ©2005  Department of Computer & Information Science Password Fields Password fields are just like textboxes ; they have the same properties, methods and react to the same events.: window.document.formName. passwordFieldName.valuePassword fields are just like textboxes ; they have the same properties, methods and react to the same events.: window.document.formName. passwordFieldName.value

Copyright ©2005  Department of Computer & Information Science Hidden Fields Sometimes, developers will include hidden fields on a web form to send information that the user doesn’t need to see. We handle such fields as if they were regular textboxes : window.document.formName. hiddenFieldName.valueSometimes, developers will include hidden fields on a web form to send information that the user doesn’t need to see. We handle such fields as if they were regular textboxes : window.document.formName. hiddenFieldName.value

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

Copyright ©2005  Department of Computer & Information Science Text Areas A textarea allows users to type multiple lines of text. To access a textarea object via JavaScript, use the same syntax as a textbox : window.document.formName. textAreaName.valueA textarea allows users to type multiple lines of text. To access a textarea object via JavaScript, use the same syntax as a textbox : window.document.formName. textAreaName.value

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

Copyright ©2005  Department of Computer & Information Science select Lists JavaScript sees the options of a select list as a zero-indexed array.JavaScript sees the options of a select list as a zero-indexed array. select lists come in two flavors – one that restricts the user to one option and the other that allows multiple options. JavaScript handles each differently …select lists come in two flavors – one that restricts the user to one option and the other that allows multiple options. JavaScript handles each differently …

Copyright ©2005  Department of Computer & Information Science Single Option select Lists To return a value from a single option select list, we would use the selectedIndex property of the select object: window.document.formName.select [select.selectedIndex].valueTo return a value from a single option select list, we would use the selectedIndex property of the select object: window.document.formName.select [select.selectedIndex].value

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

Copyright ©2005  Department of Computer & Information Science Multiple Option select Lists To return multiple values from a multiple option select list, we would use the selected property of the select object and a for loop: window.document.formName.select [forLoopCounterValue].selectedTo return multiple values from a multiple option select list, we would use the selected property of the select object and a for loop: window.document.formName.select [forLoopCounterValue].selected

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

Copyright ©2005  Department of Computer & Information Science Handling radio Buttons Programmers use radio buttons to restrict a user’s choice to a single item from among a set of multiple choices.Programmers use radio buttons to restrict a user’s choice to a single item from among a set of multiple choices. In a single set of buttons, each radio button shares its name with others in the same set. On the JavaScript side, this lends itself very well to using an array …In a single set of buttons, each radio button shares its name with others in the same set. On the JavaScript side, this lends itself very well to using an array …

Copyright ©2005  Department of Computer & Information Science Handling radio Buttons We can use the checked attribute of the radio object, in conjunction with a for loop to see which radio the user checked and report its value.We can use the checked attribute of the radio object, in conjunction with a for loop to see which radio the user checked and report its value. Although radio buttons in the same set share the same name, their values can be different.Although radio buttons in the same set share the same name, their values can be different.

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

Copyright ©2005  Department of Computer & Information Science Handling checkboxes checkboxes are similar to radio buttons (they can share the same name), but users can choose more than one.checkboxes are similar to radio buttons (they can share the same name), but users can choose more than one. We can handle checkboxes in a similar manner: using a for loop along with an if statement to check for the checked attribute and then report the value.We can handle checkboxes in a similar manner: using a for loop along with an if statement to check for the checked attribute and then report the value.

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

Copyright ©2005  Department of Computer & Information Science Summary The tag uses the action and method attributes to deliver data from a form to a processing script on a server.The tag uses the action and method attributes to deliver data from a form to a processing script on a server. We can use event handlers like onSubmit and onReset to read form values in JavaScript.We can use event handlers like onSubmit and onReset to read form values in JavaScript. continued …

Copyright ©2005  Department of Computer & Information Science Summary We can use the value attribute to read values from textboxes, password fields, hidden fields and text areas.We can use the value attribute to read values from textboxes, password fields, hidden fields and text areas. We can use for loops, along with if structures to determine the values of items in a set, like items from select objects, radio buttons or checkboxes.We can use for loops, along with if structures to determine the values of items in a set, like items from select objects, radio buttons or checkboxes.

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: