O'Reilly logo

HTML, XHTML, & CSS All-in-One For Dummies®, 2nd Edition by Andy Harris

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Getting Valid Input

In This Chapter

  • Extracting data from drop-down lists

  • Working with multiple-selection lists

  • Getting data from check boxes and radio groups

  • Validating input with regular expressions

  • Using character, boundary, and repetition operators

  • Using pattern memory

Getting input from the user is always nice, but sometimes users make mistakes. Whenever you can, you want to make the user's job easier and prevent certain kinds of mistakes.

Fortunately, you can take advantage of several tools designed exactly for that purpose. In this chapter, you discover two main strategies for improving user input: specialized input elements and pattern-matching. Together, these tools can help ensure that the data the user enters is useful and valid.

Getting Input from a Drop-Down List

The most obvious way to ensure that the user enters something valid is to supply him with valid choices. The drop-down list is an obvious and easy way to do this, as you can see from Figure 6-1.

The list-box approach has a lot of advantages over text field input:

  • The user can input with the mouse, which is faster and easier than typing.

  • You shouldn't have any spelling errors because the user didn't type the response.

  • The user knows all the answers available because they're listed.

  • You can be sure the user gives you a valid answer because you supplied the possible responses.

  • User responses can be mapped to more complex values — for example, you can show the user Red and have the list box return the hex value #FF0000 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required