11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

action="http://www.javascriptref.com"<br />

onsubmit="return validate();">><br />

Username:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<strong>The</strong> nice thing about this approach is that it‘s easy to add these validation routines to just about<br />

any page. Just place the script in the page, customize the validations[] array to hold the form<br />

fields you wish to validate and the string to indicate the validation to perform, and finally add the<br />

call to validate() as the onsubmit handler for your form. Separating the mechanism of<br />

validation (the checking functions) from the policy (which fields to check for what) leads to<br />

reusability and decreased maintenance costs in the long run.

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

Saved successfully!

Ooh no, something went wrong!