
761
DEVELOPING
COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Las
t
upda
te
d 8/5/2010
}
//-->
</script>
</head>
<body>
<h2>JavaScript validation test</h2>
<!--- Form is submitted only if the password is valid. --->
<cfif IsDefined("Form.passwd1")>
<p>Your Password if valid.</p>
</cfif>
<p>Please enter your new password:</p>
<cfform name="UpdateForm" preservedata="Yes" >
<!--- The onValidate attribute specifies the JavaScript validation
function. The message attribute is the message that appears
if the validation function returns False. --->
<cfinput type="password" name="passwd1" required="YES"
onValidate="testpasswd"
message="Your password must have 8-12 characters and include uppercase
and lowercase letters and at least one number."
size="13" maxlength="12">
<input type="Submit" value=" Update... ">
</cfform>
</body>
</html>
2
Save the page as validjs.cfm.
3
View the validjs.cfm page in your browser.
Handling failed validation
The
onError
attribute lets you specify a JavaScript function to execute if an onValidate, onBlur, or onSubmit
validation fails. For example, if you use the
onValidate
attribute to specify a JavaScript function to handle input
validation, you can also use the
onError
attribute to specify a JavaScript function to handle a failed validation (that is,
when
onValidate
returns a False value). If you use the
onValidate
attribute, you can also use the
onError
attribute
to specify a JavaScript function that handles the validation errors. The following
cfform
tags support the
onerror
attribute:
•
cfgrid
•
cfinput
•
cfselect
•
cfslider
•
cftextinput
•
cftree
ColdFusion passes the following JavaScript objects to the function in the
onerror
attribute:
•
The JavaScript form object
•
The
name
attribute of the form element
•
The value that failed validation