HTML and JavaScript: Forms and Validation

Similar documents
HTML Forms. By Jaroslav Mohapl

CSE 154 LECTURE 8: FORMS

HTML Tables and Forms. Outline. Review. Review. Example Demo/ Walkthrough. CS 418/518 Web Programming Spring Tables to Display Data"

Spring 2014 Interim. HTML forms

DOM Primer Part 2. Contents

The Hypertext Markup Language (HTML) Part II. Hamid Zarrabi-Zadeh Web Programming Fall 2013

CITS3403 Agile Web Development Semester 1, 2018

1 Form Basics CSC309

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

By the end of this section of the practical, the students should be able to:

core programming HTML Forms Sending Data to Server-Side Programs Marty Hall, Larry Brown

Forms, CGI. Objectives

Forms, Form Events, and Validation. Bok, Jong Soon

HTML Forms. 10 September, Dr Derek Peacock. This is a short introduction into creating simple HTML forms. Most of the content is

CHAPTER 6: CREATING A WEB FORM CREATED BY L. ASMA RIKLI (ADAPTED FROM HTML, CSS, AND DYNAMIC HTML BY CAREY)

Forms, CGI. HTML forms. Form example. Form example...

Introduction to DHTML

Chapter 1 FORMS. SYS-ED/ Computer Education Techniques, Inc.

Hyperlinks, Tables, Forms and Frameworks

Forms, CGI. Cristian Bogdan 2D2052 / 2D1335 F5 1

Student, Perfect Final Exam May 25, 2006 ID: Exam No CS-081/Vickery Page 1 of 6

HTML: Fragments, Frames, and Forms. Overview

Figure 1 Forms category in the Insert panel. You set up a form by inserting it and configuring options through the Properties panel.

Row and Column Spans. Homework. Column and Row Span Example (2) Column and Row Span Example. tables: Live Demo. like the following using forms:

COMS 359: Interactive Media

Dynamic HTML becomes HTML5. HTML Forms and Server Processing. Form Submission to Web Server. DHTML - Mouse Events. CMST385: Slide Set 8: Forms

CSC Javascript

JavaScript: Events, DOM and Attaching Handlers

CITS1231 Web Technologies

HTML User Interface Controls. Interactive HTML user interfaces. Document Object Model (DOM)

Form Overview. Form Processing. The Form Element. CMPT 165: Form Basics

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

Fundamentals of Website Development

Web Site Development with HTML/JavaScrip

HTML Tables and. Chapter Pearson. Fundamentals of Web Development. Randy Connolly and Ricardo Hoar

HTML 5 Tables and Forms

CS Exam 1 Review Suggestions - Spring 2017

Web Forms. Survey or poll Contact us Sign up for an newsletter Register for an event

DAY 2. Creating Forms

Outline. Introducing Form. Introducing Forms 2/21/2013 INTRODUCTION TO WEB DEVELOPMENT AND HTML

LAB Test 1. Rules and Regulations:-

<body> <form id="myform" name="myform"> <!-- form child elements go in here --> </form> </body>

Overview of Forms. Forms are used all over the Web to: Types of forms: Accept information Provide interactivity

HTML Form. Kanida Sinmai

TEXTAREA NN 2 IE 3 DOM 1

Web Programming. Based on Notes by D. Hollinger Also Java Network Programming and Distributed Computing, Chs.. 9,10 Also Online Java Tutorial, Sun.

Dreamweaver: Web Forms

Javascript Lecture 23

LAB MANUAL SUBJECT: WEB TECHNOLOGY CLASS : T.E (COMPUTER) SEMESTER: VI

Web Site Design and Development Lecture 23. CS 0134 Fall 2018 Tues and Thurs 1:00 2:15PM

Summary 4/5. (contains info about the html)

Web Designing Course

write vs. writeln Prompting as Page Loads Today s Goals CSCI 2910 Client/Server-Side Programming Intermediate File vs. HTML Output

JavaScript: Introduction to DOM and Attaching Handlers

Forms iq Designer Training

Q1. What is JavaScript?

Practice problems. 1 Draw the output for the following code. 2. Draw the output for the following code.

UNIT-VI CREATING AND USING FORMS

Consider the following file A_Q1.html.

ITEC447 Web Projects CHAPTER 9 FORMS 1

jquery - Other Selectors In jquery the selectors are defined inside the $(" ") jquery wrapper also you have to use single quotes jquery wrapper.

Web Design and Development ACS Chapter 13. Using Forms 11/27/2018 1

Introduction to IBM Rational HATS For IBM System i (5250)

Web Development. With PHP. Web Development With PHP

INTRODUCTION TO WEB DEVELOPMENT AND HTML. Lecture 13: Intro to JavaScript - Spring 2011

JavaScript!= Java. Intro to JavaScript. What is JavaScript? Intro to JavaScript 4/17/2013 INTRODUCTION TO WEB DEVELOPMENT AND HTML

cwhois Manual Copyright Vibralogix. All rights reserved.

Controlled Assessment Task. Question 1 - Describe how this HTML code produces the form displayed in the browser.

SPARK. User Manual Ver ITLAQ Technologies

Skyway Builder Web Control Guide

chapter 7 Interacting with Users Tell me and I will forget. Show me and I will remember. Involve me and I will understand.

BOOTSTRAP FORMS. Wrap labels and controls in a <div> with class.form-group. This is needed for optimum spacing.

COMP1000 Mid-Session Test 2017s1

JAVASCRIPT BASICS. Handling Events In JavaScript. In programing, event-driven programming could be a programming

Programmazione Web a.a. 2017/2018 HTML5

Outline of Lecture 5. Course Content. Objectives of Lecture 6 CGI and HTML Forms

CSC Web Technologies, Spring HTML Review

Chapter 3 HTML Multimedia and Inputs

Creating Better Forms; an article for developers 2010

Dynamic Form Processing Tool Version 5.0 November 2014

Manual Html A Href Onclick Submit Form

MARKING SCHEME Subject: Information and Communication Technology (ICT) Class: X ( )

Creating and Building Websites

D B M G. Introduction to databases. Web programming: the HTML language. Web programming. The HTML Politecnico di Torino 1

Produced by. App Development & Modeling. BSc in Applied Computing. Eamonn de Leastar

CSS Review. Objec(ves. Iden(fy the Errors. Fixed CSS. CSS Organiza(on

Programming in HTML5 with JavaScript and CSS3

HTML forms and the dynamic web

Forms 4/3/2018. Two way communication. Sending Data from Client to Server. One way communication:

EECS1012. Net-centric Introduction to Computing. Lecture JavaScript Events

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore

Notes General. IS 651: Distributed Systems 1

Session 10. Form Dataset. Lecture Objectives

1. Cascading Style Sheet and JavaScript

Table Basics. The structure of an table

COM1004 Web and Internet Technology

JavaScript & DHTML Cookbool(

Collecting Information with Forms

SilkTest 2009 R2. Rules for Object Recognition

Transcription:

HTML and JavaScript: Forms and Validation CISC 282 October 18, 2017 Forms Collection of specific elements know as controls Allow the user to enter information Submit the data to a web server Controls are usually assigned names via an attribute <controltag name="controlname" /> <controltag name="controlname" > </controltag> Should name each control whose data will be submitted A name may not be entirely unique May be applied to a series of elements representing different values for the same property 2

Forms Information is sent to the server as a query string Series of name/value pairs Automatically generated upon submission <form action="appurl" method="submitmethod">... </form> appurl is the URL of an application on a web server The program that will manage the form data server-side form is a block element All controls are inline submitmethod must either be get or post 3 get and post get Default if no other method is specified Submits query string appended to appurl appurl?name1=value1&...&namen=valuen Can also pass information to servers without forms May hit a limit on the length of the URL Some servers may truncate the query string if it is too long post Submits query string separately from appurl The user doesn't see it No limits on length Generally seen as more secure 4

Input Controls <input type="inputtype" attributes /> Represents a wide range of control elements Boxes, buttons, etc. The variety of the element depends on inputtype The same can be said for its attributes and properties HTML and DOM Behaviour also depends on inputtype tel engages the keypad for input on phones email automatically does some address validation 5 Text Box <input type="text" /> Creates a single-line text input area The user can type in a small amount of data HTML attributes value: initial text placed in the box size: number of visible characters before scrolling maxlength: number of characters that may be entered DOM Properties value: the content of the text box disabled: whether the user may enter text or not 6

Checkboxes <input type="checkbox" /> description Creates a checkbox with description as a label The user may check or uncheck the box Value in query string is "on" if checked e.g., &name=on& No value submitted if unchecked HTML attributes checked: box is initially checked DOM Properties checked: whether the box is checked or not 7 Radio Buttons <input type="radio" name="groupname" value="buttonvalue" /> description Creates a radio button with description as a label Use the same groupname for a group of buttons Only one may be selected at any time Query string will contain single value for the group e.g.,...&groupname=buttonvalue&... HTML attributes value: value submitted in query string (default is "on") DOM Properties checked: whether the button is selected or not 8

Labels <label> control and description </label> <label for= controlid > description </label> Makes a control's description "clickable" Click to select a checkbox, radio button, Why use labels? Adds functionality Can apply tag-specific style with CSS Helps screen readers better describe forms 9 Text Area <textarea rows="numrows" cols="numcols" > initialtext </textarea> Creates a multi-line text input area The user can type in a large amount of data Size is specified numrows lines high and numcols characters wide Vertical scrollbar appears if more text is entered DOM Properties value: the content of the text area disabled: whether the user may enter text or not cols/rows: the width/height of the text area (as String) 10

Menus and Lists <select name="menuname" > <option value="value1">entry1</option> <option value="valuen">entryn</option> </select> Creates a menu with the given entries Default is a drop-down menu Lists are created by specifying the size attribute Sets number of entries shown at once e.g., <select size="5"...> Permit multiple selection via attribute multiple e.g., <select size="5" name="x[]" multiple> 11 Menus and Lists <select name="menuname" > <option value="value1">entry1</option> <option value="valuen">entryn</option> </select> Options are specified like list items Use selected attribute to specify an initial selection e.g., <option selected...> value is sent in the query string 12

submit and reset <input type="submit" value="buttontext"/> <input type="reset" value="buttontext"/> Submit button tells the form to process the data Creates the query string Taken from the names and values of the elements Sends it to the server Done via get or post Uses provided appurl in form Reset button clears the contents of the form Restores all controls to default values 13 Some Useful Things Styling Tables were often used to organize forms A better approach is to use CSS More flexible Gives finer control <input type="hidden" name="..." value="..."/> A control that is never displayed Useful for sending additional data to the server HTML5 input attribute required Form will not submit with an empty value in that field 14

Some Useful Things Groups controls with a similar purpose or theme Draws a box around them Labels the box with caption Can be styled using CSS <input type="button" value="buttontext"...> <fieldset> <legend>caption</legend> controls </fieldset> Creates a button labelled buttontext Use to perform some action Can link to a JavaScript function via the click event 15 Form Events Name The User Must Applicable Elements focus / blur change Apply/lose focus (e.g., click in/out of a text field) apply focus to a control, alter the value and remove focus reset reset the form <form> submit submit the form <form> Many HTML elements Most <input>s, <textarea> and <select> Can also apply mouse and keyboard events to many controls 16

Three Phases of Validation As the user types or selects data Manage events such as onkeydown, onclick, etc. Test current value against desired format As the user finishes altering existing data Manage the change event Test current value against desired format As the user submits the form Manage the submit event Test all values against desired formats 17 Three Phases of Validation The first two phases allow you to warn the user Alert him or her to errors before attempting to submit Try to be obvious without hindering functionality Strategies Dynamically alter a status message in the document Dynamically alter the control's style The last phase prevents submission of invalid data Return true or false in a handler for submit Can use onsubmit="return handler()" in the HTML HTML5 also includes the concept of constraint validation Not currently well-supported in Safari 18