22.04.2013 Views

HTML, XHTML & CSS

HTML, XHTML & CSS

HTML, XHTML & CSS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 14: Working with Forms<br />

The whole point of a form is to gather values associated with input controls,<br />

so how you set the name and value for each control is important. The following<br />

sections explain how you should work with names and values for each of<br />

the input controls.<br />

The input element (and by extension, the empty tag) is the<br />

major player when it comes to using <strong>HTML</strong> forms to solicit user input. Inside<br />

the input element is where you define the kinds of input you want to collect,<br />

and how you package and present the input fields and cues you present to<br />

users so they can give you what you’re asking for.<br />

Input fields<br />

You can use a variety of input fields in your forms, such as text, password,<br />

radio buttons/check boxes, hidden, and more. Not all fields require values for<br />

name and type attributes (for example, text box or password fields), but it’s<br />

a good idea to provide users with explanatory labels and examples of input<br />

data any time they might have questions about formats — as when pondering<br />

whether or not to include dashes or spaces in credit card or telephone<br />

numbers. Check boxes and radio buttons, on the other hand, require such<br />

information so they can be properly labeled when the browser shows users<br />

what selections are available.<br />

For input elements that require a user to select an option (a check box or<br />

radio button) rather than typing something into a field, you define both the<br />

name and the value. When the user selects a check box or a radio button and<br />

then clicks the Submit button, the form returns the name and value assigned<br />

to the element.<br />

We discuss these two types of input fields in the upcoming section, “Check<br />

boxes and radio buttons.”<br />

Text fields<br />

Text fields are single-line fields in which users type information. When you<br />

need to offer the user the opportunity to fill in more than one line, you use a<br />

text box, as we discuss in the upcoming section, “Multiline text boxes.”<br />

Here’s how to create a single-line text field:<br />

1. Define the input type as a text field by using the element<br />

with the type attribute set to text.<br />

<br />

2. Then use the name attribute to give the input field a name.<br />

<br />

The user supplies the value when she types in the field.<br />

227

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!