144
Chapter 9 Building Dynamic Forms
Input Validation with JavaScript
In addition to native ColdFusion input validation using the
validate
attribute of the
cfinput
and
cftextinput
tags, the following tags support the
onvalidate
attribute,
which allows you to specify a JavaScript function to handle your
cfform
input
validation:
•
cfgrid
•
cfinput
•
cfslider
•
cftextinput
•
cftree
ColdFusion passes the following JavaScript objects to the JavaScript function you
specify in the
onvalidate
attribute:
•
form_object (the form)
•
input_object (the tag whose value is being validated)
•
object_value (the value to validate)
Handling failed validation
The
onerror
attribute allows you to specify a JavaScript function to execute if a
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 are using the
validate
attribute you can
also use the
onerror
attribute to specify a JavaScript function handle 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:
•
form_object
•
input_object
•
object_value
•
error message text
Example: validating an e-mail address
The following example validates an e-mail entry. If the string is invalid it displays a
message box. If the address is valid it redisplays the page.
Summary of Contents for COLDFUSION 5-DEVELOPING
Page 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Page 58: ...38 Chapter 3 Querying a Database ...
Page 134: ...114 Chapter 7 Updating Your Database ...
Page 210: ...190 Chapter 10 Reusing Code ...
Page 232: ...212 Chapter 11 Preventing and Handling Errors ...
Page 238: ...218 Chapter 12 Using the Application Framework ...
Page 262: ...242 Chapter 12 Using the Application Framework ...
Page 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Page 320: ...300 Chapter 15 Indexing and Searching Data ...
Page 336: ...316 Chapter 16 Sending and Receiving E mail ...
Page 374: ...354 Chapter 18 Interacting with Remote Servers ...