magazine resources subscribe about advertising

New Architect Daily
Commentary and updates on current events and technologies

CMP Media E-Book

Download your copy today.

Research
Search for reports and white papers from industry vendors and analysts.

This Week at NewArchitect.com Subscribe now to our free email newsletter and get notified when the site is updated with new articles







Day of Defeat Online Gaming

 New Architect > Archives > 1998 > 01 > Script Junkie  

Filtering Input in JavaScript 1.2

By Reaz Hoque

Invariably, some visitors will input data incorrectly in HTML forms, so there's no getting around validating the input. You can use CGI for validation, but that requires the user to submit the form and wait until the server confirms the validation. I strongly suggest validating with client-side JavaScript, which allows incorrect input to be flagged to the user immediately.

Changes in JavaScript 1.2 mean that you can filter the input while the user is inputting data. For example, to ensure that a field accepts only numbers, you can create a filter that causes the field not to be affected if the user hits any keys except 0-9. This is an improvement over JavaScript 1.1, in which you had to hit a button for a function to check the field for nonnumeric characters.

The Event Object

The event object exists only in JavaScript 1.2. Like other JavaScript objects, it contains properties. Each property describes a JavaScript event, and is passed as an argument to an event handler when the event occurs. For example, if the mouseDown event occurs in an image object, the event object will contain the type of event, the cursor position, and a field denoting the modifier key pressed at the time of the event. Table 1 lists all the event handlers in JavaScript 1.2, while



  Day of Defeat Online Gaming

home | daily | current issue | archives | features | critical decisions | case studies | expert opinion | reviews | access | industry events | newsletter | research | careers | info centers | advertising | subscribe | subscriber service | editorial calendar | press | contacts


Copyright © 2006 CMP Media, LLC Read our privacy policy, your California privacy rights, terms of service.
SDMG Web sites: BYTE.com, C/C++ Users Journal, Developer Pipeline, Dr. Dobb's Journal, DotNetJunkies, MSDN Magazine, Sys Admin,
SD Expo, SD Magazine, SqlJunkies, The Perl Journal, Unixreview, Windows Developer Network, New Architect

web2