128
Developing Web Applications with ColdFusion
To use JavaScript to validate form data:
1.
Create a new file in Studio.
2.
Edit the page so that it appears as follows:
<HTML>
<HEAD>
<TITLE>JavaScript Validation</TITLE>
4
<SCRIPT>
<!--
function testbox(form) {
4
Ctrl = form.inputbox1;
4
if (Ctrl.value == "" || Ctrl.value.indexOf (’@’, 0) == -1) {
4
return (false);
4
} else
4
return (true);
4
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<H2>JavaScript validation test</H2>
<P>Please enter your email address:</P>
<CFFORM NAME="UpdateForm"
ACTION="update.cfm" >
<CFINPUT TYPE="text"
NAME="inputbox1"
REQUIRED="YES"
4
ONVALIDATE="testbox"
MESSAGE="Sorry, invalid entry."
SIZE="10"
MAXLENGTH="10">
<INPUT TYPE="Submit" VALUE=" Update... ">
</CFFORM>
</BODY>
</HTML>
3.
Save the page as
validjs.cfm
.
4.
View
validjs.cfm
in your browser.
When you enter an invalid email address, an error appears. Even if you enter a
valide email address, and Error 404 appears because you haven’t created the
action page
update.cfm
.
Summary of Contents for COLDFUSION 4.5-DEVELOPING WEB
Page 1: ...Allaire Corporation Developing Web Applications with ColdFusion ColdFusion 4 5...
Page 14: ...xiv Developing Web Applications with ColdFusion...
Page 26: ...xxvi Developing Web Applications with ColdFusion...
Page 34: ...8 Developing Web Applications with ColdFusion...
Page 70: ...44 Developing Web Applications with ColdFusion...
Page 84: ...58 Developing Web Applications with ColdFusion...
Page 114: ...88 Developing Web Applications with ColdFusion...
Page 148: ...122 Developing Web Applications with ColdFusion...
Page 174: ...148 Developing Web Applications with ColdFusion...
Page 208: ...182 Developing Web Applications with ColdFusion...
Page 244: ...218 Developing Web Applications with ColdFusion...
Page 274: ...248 Developing Web Applications with ColdFusion...
Page 288: ...262 Developing Web Applications with ColdFusion...
Page 300: ...274 Developing Web Applications with ColdFusion...
Page 350: ...324 Developing Web Applications with ColdFusion...
Page 362: ...336 Developing Web Applications with ColdFusion...