HTML Forms, Part 1 Image taken from "How to structure an HTML form" from Mozilla Developer Network.

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

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.
Tutorial 6 Creating a Web Form
Events Part III The event object. Learning Objectives By the end of this lecture, you should be able to: – Learn to use the hover() function – Work with.
SE-2840 Dr. Mark L. Hornick 1 HTML input elements and forms.
Supplement Creating Forms. Objectives Show how forms are used How to create the Form element HTML elements used for creating input fields.
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.
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.
Tutorial 6 Working with Web Forms
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.
USER INTERACTIONS: FORMS
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
XHTML Forms for Data Collection and Submission Chapter 5.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
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.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
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.
HTML II. Factors to consider in designing a website. Organizing your files. HTML Tables. Unordered Lists. Ordered Lists. HTML Forms. Learning Objectives.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
HTML Forms.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
FORMS. Forms are used to receive information from the web surfer, such as: their name, address, credit card, etc. Form fields are objects that allow.
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.
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.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Project 6 Creating Forms on a Web Page. Objectives Define terms related to forms Describe the different form controls and their uses Use the tag Create.
HTML Creating Forms on a Web Page. 2 Objectives  Discuss the process of creating a form  Distinguish between data input controls and text input controls.
HTML Forms.
Week 10: HTML Forms HNDIT11062 – Web Development.
HTML Forms. A form is simply an area that can contain form fields. Form fields are objects that allow the visitor to enter information - for example text.
Review of HTML and CSS A (very) brief review of some key fundamentals to be aware of in IT-238.
Creating Forms on a Web Page. 2 Introduction  Forms allow Web developers to collect visitor feedback  Forms create an environment that invites people.
XP Tutorial 6New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
Intro to Dynamic HTML Forms - Part 1
Tutorial 6 Working with Web Forms
Section 10.1 Define scripting
Creating and Processing Web Forms
Advanced HTML Tags:.
Intro to Dynamic HTML Intro to Forms
In this session, you will learn to:
How to Write Web Forms By Mimi Opkins.
Objectives Design a form Create a form Create text fields
HTML Forms CSC 102 Lecture.
Retrieving information from forms
HTML/XHTML Forms 18-Sep-18.
Designing Forms Lesson 10.
HTML Forms and User Input
Web Development & Design Foundations with H T M L 5
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.
CNIT 131 HTML5 - Forms.
Teaching slides Chapter 6.
Creating Forms on a Web Page
© Hugh McCabe 2000 Web Authoring Lecture 8
Events Part III The event object.
JavaScript Part 2 Organizing JavaScript Code into Functions
Retrieving information from forms
Checkboxes, Select boxes, Radio buttons
Presentation transcript:

HTML Forms, Part 1 Image taken from "How to structure an HTML form" from Mozilla Developer Network.

Learning Objectives By the end of this lecture, you should be able to: Create a basic form with text fields, text areas, and buttons Understand the need for the <label> tag, and the for attribute Describe what is meant by “programming conventions” Apply programming conventions when creating a web form Describe the next step that must occur in order for an HTML form to be able to “do something”

Example: The BMR Calculator A form Allows the user to enter some information about themselves and estimates the their basal metabolic rate (the number of calories their body consumes at rest in a day). Dynamic HTML being used: A form to enter data A client-side JavaScript that parses the form and uses the data to come up with a calculated value http://www.drgily.com/basal-metabolic-rate-calculator.php Note: This URL may change. FYI: Calculating BMR is a debated topic in medical/nutrition circles. Be careful of which formula you use.

Another example – CDM Tutor Search Form: The user selects a subject from the select box. In response to this choice, the form queries a database and returns a list of tutors who can help with that particular subject.

FORMS Our first venture into creating interactive/dynamic web pages. Web page takes input from the user and processes it in some way: Calculator (e.g. BMR, Mortgage, etc) Stores information in a database (registering a purchased product, signing up for a mailing list) Submits information (e-mail customer support)

Overview of Forms Forms are made up of a group of HTML elements that allow the person viewing the page to supply information. Form elements include things like buttons, text-boxes, drop-down boxes (also known as "select boxes“), check-boxes, radio buttons, etc. The HTML code to place these elements on a page is pretty straight-forward. Creating HTML forms is not difficult. However, doing something with the information that has been entered into a form requires writing instructions in the form of a scripting or a programming language such as JavaScript or PHP. For now we’ll focus on learning the elements to create and layout a form on your web page. Once we begin JavaScript you will learn how to make your web pages respond to input from a form.

Basic Form (incomplete) <form> <input type="text" > <input type="button" > <!-- other elements here…--> </form> The ‘form’ tag groups the all of the elements of a form together.

Form Element: Text Boxes <input type="text" id="txtFirstName"> We must be sure to include a prompt before the text box, e.g. “Name:”. This prompt must be placed inside a <label> tag (discussed shortly). Optional attributes include maxlength: sets the maximum value of characters It’s a good idea to include this attribute as the default value for this attribute is unlimited! size: sets the length of the box

Form Element: Buttons <input type="button" id="btnSubmit" value="Submit My Application"> We will pretty much always want to include the ‘value’ attribute. This value becomes the text that is displayed inside the button.

(but still incomplete…) Basic form, better (but still incomplete…) <form id="userInformation"> <input type="text" id="txtFirstName"> <input type="text" id="txtLastName"> <input type="button" id="btnSubmit"> </form> Note how each element has an ‘id’ attribute Note that our form elements include an id attribute. We will use this ID value when we want to pass information entered into the form to a script (which is almost always the case). For this reason, nearly every single form element (with perhaps an occasional exception) should have an id attribute. Important: Also note the conventions we use when naming our form elements: Button names begin with btn Text names begin with txt First word must begin with a lower-case letter Subsequent words are separated by capital letters More on naming conventions for form elements later….

Basic Form (pretty good) <form id="userInformation"> <label for="txtFirstName"> First Name? </label> <input type="text" id="txtFirstName"> <label for="txtLastName"> Last Name? <input type="text" id="txtLastName"> <input type="button" id="btnSubmit" value="Submit"> </form> Our prompts (e.g. First Name, Last Name, etc) will display just fine without the <label> element. However, this element is required for this course (as well as by many web design firms) for purposes of adhering to accessibility requirements, better code validation, and simply "good practices". Note that the value of the for attribute from the <label> tag must match up with the id value used in the corresponding form element.

Form Element: Text Areas Similar to text boxes, but allows the user to type in multiple lines of information. Instead of <input> tag, uses <textarea> tag. Optional attributes include cols and rows to specify the initial size of the box. (Not always precise). <textarea id="txtarComments" cols="25" rows="5"> </textarea> Note: The textarea tag requires a closing tag. That is, even though there is no content present inside the open <textarea> and closing </textarea>, we still need to include this closing tag.

Getting your button to actually do something Placing a button on the HTML page simply displays the button. To make the button actually do something we need to: Create a script Connect the button to our script The purpose of a form is to take the information entered by the user and do something with it. Reading (a.k.a. “parsing”) the form and then actually “doing” something with that information is usually the job of a script. In this course, we will typically connect our form to a JavaScript via our buttons. Here is a sneak preview: <input type= " button" value="Submit Form" id= " btnSubmit " onclick= "runSomeScript()" > More on this in JavaScript Part 1

Programming Conventions In programming it is a very good idea to come up with a consistent style of doing things. A convention means that it is considered desirable – even necessary – to consistently do things a certain way. However, a convention means that it is a choice. That is, the code will work even without adhering to these conventions. However, when a company, or team leader, etc asks a programmer to adhere to a convention, then it is considered very poor form to deviate. Programmers who are careful and consistent with adhering to designated conventions are noticed by hiring managers, colleagues, and others. We will require certain conventions in this course. In fact, you have already encountered one of them: Our naming conventions for file names in which we require that all file names are lower case, and that spaces between words should use an underscore character. e.g. my_first_page.html We will now add an additional naming convention, one that is to be used whenever naming form elements. Sometimes a project manager will dictate these kinds of conventions. Other times it is up to you to decide on one. However, it is an excellent idea to have one as it will help clarify your coding. In this course, you MUST follow programming conventions once they are introduced. In the “real” world, it looks sloppy/careless/unprofessional when programmers fail to follow conventions. Many will thank you: Project collaborators Later debuggers You! (down the road)

This course's required programming convention for naming form elements For this course you are required to use the following convention when naming form elements: Buttons: btnName Text boxes: txtName Text areas: txtarName Checkboxes: chkName Radio buttons: radName Select menu: selName Form elements not specified here: You may choose your own prefix. Note: These conventions are my own (although others may use something similar). If, in the "real world" you encounter a different convention used by whichever team you are working with, you should, of course, adhere to theirs.

File: simple_form.html <h1>Mailing List Sign-Up</h1> <form id="mailingList"> <p> <label for="txtFirstName">First Name:</label> <input type="text" id="txtFirstName"> </p> <p><label for="txtLastName">Last Name:</label> <input type="text" id="txtLastName"></p> <p><label for="txtEmail">E-mail:</label> <input type="text" id="txtEmail"></p> <p><label for="txtarReferral"> How did you hear about us?</label></p> <p><textarea id="txtarReferral"> </textarea></p> <input type="button" value="Sign Up" id="btnSignUp"> </form> Some Notes I have used a couple of different examples of whitespace here. As long as your code is clear and easy to follow, any technique you choose is fine! (Just don’t overdo it with too much whitespace!) Separating form elements with a <p> tag can be useful. Every form element should have a prompt (e.g. Name, Email, etc) Prompts should be inside a <label> tag. Every label tag should include the for attribute that is matched with the id attribute of the corresponding form element. The fact that the form elements do not neatly line up on the page may bother you – and that’s a good thing! Doing so requires a certain degree of CSS skill.