MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual page 165

Table of Contents

Advertisement

Input Validation with JavaScript
To use JavaScript to validate form data:
1
2
3
4
Create a new file in ColdFusion Studio.
Edit the page so that it appears as follows:
<html>
<head>
<title>JavaScript Validation</title>
<script>
<!--
function testbox(form) {
Ctrl = form.inputbox1;
if (Ctrl.value == "" || Ctrl.value.indexOf ('@', 1) == -1 ||
Ctrl.value.indexOf ('.', 3) == -1)
{
return (false);
}
else
{
return (true);
}
}
//-->
</script>
</head>
<body>
<h2>JavaScript validation test</h2>
<p>Please enter your email address:</p>
<cfform name="UpdateForm" preservedata="Yes"
action="validjs.cfm" >
<cfinput type="text"
name="inputbox1"
required="YES"
onvalidate="testbox"
message="Sorry, your entry is not a valid email address."
size="15"
maxlength="30">
<input type="Submit" value=" Update... ">
</cfform>
</body>
</html>
Save the page as
validjs.cfm
View
in your browser.
validjs.cfm
.
145

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 5

Table of Contents