How to cite a web site - 1151Chapter 43 .Data-Entry Validation Keyboard event monitoring isn t

1151Chapter 43 .Data-Entry Validation Keyboard event monitoring isn t practical for most validation actions, however. For example, if the user is supposed to enter an e-mail address, you need to vali date the complete entry for the presence of an @symbol (via the onChange event handler). On the other hand, you can be granular about your validations and use both the onChangeand onKeyPress event handlers; you employ the latter for blocking invalid characters in e-mail addresses (such as spaces). Batch mode validation In all scriptable browsers, the onSubmitevent handler cancels the submission if the handler evaluates to return false. Additional submission event cancelers include setting the IE4+ event.returnValue property to false and invoking the evt.preventDefault() method in NN6 (see Chapter 29 on event objects for details). You can see an example of the basic return false behavior in Listing 23-4 of Chapter 23. That example uses the results of a window.confirm()dialog box to determine the return value of the event handler. But you can also use a return value from a series of individual text box validation functions. If any one of the validations fails, the user is alerted and the submission is canceled. Before you worry about two versions of validation routines loading down the scripts in your page, you ll be happy to know that you can reuse the same valida tion routines in both the real-time and batch validations. Later in this chapter, I demonstrate what I call industrial-strength data-entry validation adapted from a real intranet application. But before you get there, you should learn about general validation techniques that you can apply to both types of validations. Designing Filters The job of writing data-validation routines essentially involves designing filters that weed out characters or entries that don t fit your programming scheme. Whenever your filter detects an incorrect entry, it should alert the user about the nature of the problem and enable the user to correct the entry. Before you put a text or TEXTAREA object into your document that invites users to enter data, you must decide if any possible entry can disturb the execution of the rest of your scripts. For example, if your script must have a number from that field to perform calculations, you must filter out any entry that contains letters or punctuation except for periods if the program can accept floating-point numbers. Your task is to anticipate every possible entry users can make and allow only those entries your scripts can use. Not every entry field needs a data-validation filter. For example, you may prompt a user for information that is eventually stored as a document.cookie or in a string database field on the server for future retrieval. If no further processing takes place on that information, you may not have to worry about the specific contents of that field. One other design consideration is whether a text field is even the proper user interface element for the data required of the user. If the range of choices for a user entry is small (a dozen or fewer), a more sensible method is to avoid the data-entry problem altogether by turning that field into a SELECT element. Your HTML attributes for the object ensure that you control the kind of entry made to that object. As long as your script knows how to deal with each of the options defined for that object, you re in the clear.
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

Leave a Reply