The conditional statement General form: if ( ) { consequent-action-list } Actual Example: if (document.getElemendById(‘name’).value= ='') { alert(‘Name.

Slides:



Advertisements
Similar presentations
Supplement Creating Forms. Objectives Show how forms are used How to create the Form element HTML elements used for creating input fields.
Advertisements

Capturing user input: Using HTML FORMs User input Up till now, our HTML documents have all been directed at outputting information to the user However,
The SELECT element This type of element merely offers another way of capturing the kinds of user-selection that we have already seen how to capture with.
Creating Web Page Forms. Objectives Describe how Web forms can interact with a server-based program Insert a form into a Web page Create and format a.
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.
Capturing user input: Using HTML FORMs CS4320 got here on 27/11/2003.
More JavaScript. JavaScript and HTML forms One of the most common usages of JavaScript is to respond to user actions when completing HTML forms JavaScript.
Other types of input element There are some types of input element that we have not considered: –type='image’ –type='hidden’ We will delay dealing with.
Python and Web Programming
XHTML Forms for Data Collection and Submission Chapter 5.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Chapter 10 Form Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
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.
CST JavaScript Validating Form Data with JavaScript.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
Tutorial #9 – Creating Forms. Tutorial #8 Review – Tables Borders (table, gridlines), Border-collapse: collapse; empty-cells: show; and rowspan, colspan.
INTRODUCTION TO WEB DEVELOPMENT AND HTML Lecture 07: Forms - Spring 2011.
Week 4  Using PHP with HTML forms  Form Validation  Create your own Contact form Please Visit:
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
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.
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
CO1552 Web Application Development HTML Forms. Websites can be made more interactive by providing facilities for users to provide data To get user entered.
PHP Forms and User Input The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
1 VU. 2 CS101 Introduction to Computing Lecture 15 More on Interactive Forms (Web Development Lecture 5)
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
Suzanne J. Sultan Javascript Lecture 2. Suzanne J. Sultan function What is a function> Types of functions:  Function with no parameters  Function with.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
HTML Forms.
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
Week 9 - Form Basics Key Concepts 1. 1.Describe common uses of forms on web pages 2.Create forms on web pages using the form, input, textarea, and select.
HTML FORMS GET/POST METHODS. HTML FORMS HTML Forms HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes,
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.
TJ 3043 – Web Application Development HTML Form. 2.0 Forms A form is the usual way to communicate information from a Web browser to a server HTML has.
Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input.
1 HTML Forms
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
1 Review of Form Elements. 2 The tag Used in between tags.  Form elements(text control, buttons, etc.. ) goes here. OR  Form elements(text control,
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.
Session 8: Working with Form iNET Academy Open Source Web Development.
HTML Forms a form is a container for input elements on a web page input elements contain data that is sent to the web server for processing.
Forms Collecting Data CSS Class 5. Forms Create a form Add text box Add labels Add check boxes and radio buttons Build a drop-down list Group drop-down.
SYST Web Technologies SYST Web Technologies XHTML Forms.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
Web Page Design Forms! Website Design. Objectives What forms can do The Attributes of the form tag Using Textboxes Textareas Checkboxes Radio buttons.
+ FORMS HTML forms are used to pass data to a server. begins and ends a form Forms are made up of input elements Every input element has a name and value.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
HTML Forms.
1 HTML Forms
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.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
INTERNET APPLICATIONS CPIT405 Forms, Internal links, meta tags, search engine friendly websites.
Web Forms. Web Forms: A form allows our web visitors to submit information to us. Some examples uses for forms are to let the web user contact us, fill.
HTML III (Forms) Robin Burke ECT 270. Outline Where we are in this class Web applications HTML Forms Break Forms lab.
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.
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.
Ashima Wadhwa Java Script And Forms. Introduction Forms: –One of the most common Web page elements used with JavaScript –Typical forms you may encounter.
XP Tutorial 6New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
Objectives Design a form Create a form Create text fields
CNIT 131 HTML5 - Forms.
© Hugh McCabe 2000 Web Authoring Lecture 8
Lesson 6: Web Forms.
HTML Forms
Presentation transcript:

The conditional statement General form: if ( ) { consequent-action-list } Actual Example: if (document.getElemendById(‘name’).value= ='') { alert(‘Name is empty’) }

Conditions Many forms are possible. Equality is one type General form of equality condition: = = Actual Example: document.getElementById(‘name’).value= ='’ Note that, in conditions, equality is written as two = characters, that is as = =

More on conditions Besides = = (for equality) we can use these other types of comparison operators in conditions: != not equal < less than > greater than <= less than or equal to >= greater than or equal to

More on conditions We can also build compound conditions using the following logical operators: && logical and || logical or ! logical not Examples: document.getElementById(‘name’)value = = ‘Fred’ || document.getElementById(‘name’).value==‘Tom’ document.getElementById(‘age’).value >= 16 && document.getElementById(‘age’).value <= 20

Alert actions General form of alert action: alert( ) Actual Examples: alert(‘Name is empty’) alert(document.getElementById(‘age’).value)

Complete docmn’t spec (Part I) Membership Application Form form {background-color : red; padding : 0.2in} fieldset {padding : 0.2in} button {margin : 0.1in} function checkApplication() { if (document.getElementById(‘name’).value=='') { alert("Name is empty"); } if (document.getElementById(‘ ’).value=='') { alert(" address is empty"); } }

Complete docmn’t spec (Part II) If you want to join our club, complete the form below and we will get back to you. Membership Application Form Contact Information What is your name? Please enter your address:

Complete docmn’t spec (Part III) Form Submission Check application Submit application

The size attribute In the examples so far, input elements of type=text were given, on the form, a user-input box of a default size You can, however, specify the exact size you want, by using the attribute size Examples: You can see the effect of these size specifications on the next slide WARNING: Some versions of Microsoft Internet Explorer actually makes user-input boxes one character longer than your specified size!

Length of user-input versus size of user-input box The user’s input is not restricted to the size of the user-input box On the next four slides, you can see, from the server-side responses, that the user input names which were much longer than the user-input box

User’s input exceeds default size of user-input box

Here we can see how long the user’s name really was

User’s input can exceed a box of specified size too:

Again, we see the full-name:

We can, however, impose an upper-limit on the user’s input: We can use the MAXLENGTH attribute Example <input type=‘text’ name=‘localPhoneNumber’ id=‘localPhoneNumber’ size=‘6’ maxlength=‘6’> This is used on the next slide: –when the user tries to input more than 6 characters in this box the browser refuses to accept them (even though the form shows the box as longer than 6 characters!)

More types of input elements

Of course, the server does not send the password back:

INPUTs of type=checkbox An input element of type=checkbox produces a little box into which the user can place a mark to indicate a desire to select the value that is associated with the element This type of element must have a value attribute to specify the associated value Example If the user places a in the box produced by this element the server-side program would be told that the user selected navyBlue as a colour Three check-boxes are used on the next slide

Using the checkboxes By clicking on one or more of these checkboxes, the user can select one or more T-shirts that he wants to order

Form Specification Order What is your name? Please select which style(s) of T-shirt you want: <input type=‘checkbox’ name=‘products’ value=‘Batman’> Batman's cloak <input type=‘checkbox’ name=‘products’ value=‘Superman’> Superman’s cloak <input type=‘checkbox’ name=‘products’ value=‘Dr. Who’> Dr. Who's coat Form Submission Submit order

If we want to use JavaScript with the checkboxes, we must give each one a separate ID Order What is your name? Please select which style(s) of T-shirt you want: <input type=‘checkbox’ name=‘products’ id=‘products1’ value=‘Batman’> Batman's cloak <input type=‘checkbox’ name=‘products’ id=‘products2’ value=‘Superman’> Superman’s cloak <input type=‘checkbox’ name=‘products’ id=‘products3’ value=‘Dr. Who’> Dr. Who's coat Form Submission Submit order

Oh, by the way: On the screen below, we eliminate list “bullets” by the following line in a stylesheet li {list-style-type : none}

Using text with checkboxes You must use text with checkboxes –otherwise, the user will not know what he is selecting –this is because the value associated with the checkbox is not printed by a browser Example: Batman's cloak The user sees Batman's cloak in the browser beside the checkbox

Multiple checkboxes with same name Notice that we can have multiple checkboxes with the same name: Batman's cloak Superman’s cloak Dr. Who's coat If the user selects more than one checkbox with the same name, several equations involving this name are sent to the server-side program, e.g.: products=Batman products=Superman

If we want to send the data to a PHP program, we must [] in the name of the checkboxes Order What is your name? Please select which style(s) of T-shirt you want: <input type=‘checkbox’ name=‘products[]’ value=‘Batman’> Batman's cloak <input type=‘checkbox’ name=‘products[]’ value=‘Superman’> Superman’s cloak <input type=‘checkbox’ name=‘products[]’ value=‘Dr. Who’> Dr. Who's coat Form Submission Submit order

A PHP program which can handle several checked checkboxes with the same name

Complete programme (top-level) Product ordering Product ordering <?php $customerName=$_POST['customerName']; if (!$customerName) { ……………. } else { ……………. } ?>

Complete programme (then-part) ?> Order What is your name? Please select which style(s) of T-shirt you want: <input type='checkbox' name='products[]' value='Batman'> Batman's cloak <input type='checkbox' name='products[]' value='Superman'> Supermans cloak <input type='checkbox' name='products[]' value='Dr. Who'> Dr. Who's coat Form Submission Submit order <?php

Complete programme (else-part) $products=$_POST['products']; $nProducts=count($products); echo " Welcome, $customerName. "; echo " You selected $nProducts product(s). "; if ($nProducts >0) { echo " These were:"; echo " "; $counter=0; while ($counter<$nProducts) { echo " "; echo $products[$counter]; echo " "; $counter=$counter+1; } echo " "; }

Style sheet form {background-color:red; padding:0.2in } fieldset { padding:0.2in } li { list-style-type : none }

Of course, top-down programming is easier

Complete programme (page 1) Product ordering Product ordering <?php $customerName=$_POST['customerName']; if (!$customerName) { printForm(); } else {$products=$_POST['products']; reportOrder($customerName,$products); } ?>

Complete programme (page 2) <?php function printForm() { ?> Order What is your name? Please select which style(s) of T-shirt you want: <input type='checkbox' name='products[]' value='Batman'> Batman's cloak <input type='checkbox' name='products[]' value='Superman'> Supermans cloak <input type='checkbox' name='products[]' value='Dr. Who'> Dr. Who's coat Form Submission Submit order <?php }

Complete programme (page 3) function reportorder($customerName,$products) { $nProducts=count($products); echo " Welcome, $customerName. "; echo " You selected $nProducts product(s). "; if ($nProducts >0) { echo " These were:"; echo " "; $counter=0; while ($counter<$nProducts) { echo " "; echo $products[$counter]; echo " "; $counter=$counter+1; } echo " "; } ?>

Default selection of checkboxes The web page on the next slide is trying to encourage the user to buy the Superman T- shirt It does so by “pre-selecting” the checkbox for this T-shirt and by having some associated “pushy” text

More on default selection A checkbox is preselected by using the attribute CHECKED in the input element: Batman's cloak Superman's cloak (our best-selling item) Dr. Who's coat The user can, of course, remove the from a checkbox by clicking on the box

input elements of type=radio The word radio derives from the concept of “radio buttons” -- the station selection buttons on car-radios Properties of radio buttons: –they represent alternatives –only one alternative can be selected –selecting one alternative has the side-effect of automatically de-selecting any previous selection input elements of type=radio have the same properties

More on input elements of type=radio The following slide shows a radio button version of the previous order form Now the user can buy only one T-shirt

Suppose the user has selected the Batman T-shirt

If he now clicks the Dr. Who button, Batman is deselected

Implementation of the above: Batman's cloak Superman's cloak Dr. Who's coat

Preselection of radio buttons Just as checkboxes can be preselected, one radio button in a group which all have the same name can be preselected HOWEVER, –more than one checkbox can be preselected –but ONLY ONE radio button can be preselected

Example Batman's cloak Superman's cloak (our best-selling item) Dr. Who's coat

Inputs of type=file

File upload script Upload a File <?php $fileName=$_FILES['myfile']['name'] if (!$myfile) { ?> Upload a File File to Upload: "Upload File“ <?php } else { $size=$_FILES['myfile']['size']; $type=$_FILES['myfile']['type']; File Received The following file has been received:, containing bytes and of MIME type. <?php } ?>