User Guide

Table Of Contents
680 Chapter 28: Validating Data
Validating form input and handling errors with JavaScript
ColdFusion MX lets you write your own validation routines in JavaScript, and lets you create
JavaScript error handlers.
Validating input with JavaScript
In addition to native ColdFusion input validation using the
validate attribute of the cfinput
and
cftextarea tags, the following tags support the onValidate attribute, which lets you specify
a JavaScript function to handle your
cfform input validation:
cfgrid
cfinput
cfslider
cftextarea
cftree
ColdFusion passes the following arguments to the JavaScript function that you specify in the
onValidate attribute:
The form JavaScript DOM object
The name attribute of the form element
The value of the control to validate
For example, if you write the
cfinput tag as the following:
<cfinput type="text"
...
<!--- Do not include () in JavaScript function name. --->
onvalidate="handleValidation"
...
>
You define the JavaScript function as the following:
<script>
<!--
function handleValidation(form_object, input_object, object_value) {
...
}
//-->
</script>
Example: validating a password
The following example validates a password. The password must have at least one of each of the
following: an uppercase letter, a lowercase letter, and a number. It must be between 8 and 12
characters long. If the password is invalid, the browser displays a message box. If the password is
valid, it redisplays the page with a brief success message.