> > Is it possible to mix html form fields and <cfinput> fields
> > in a page and use JavaScript to validate the html form fields
> > while still using <cfform> validation for <cfinput> fields?
>
> You can certainly do this. Here's an example:
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>
> <html>
> <head>
> <title>Additional Validation</title>
>
> <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
> <!--
>
> function validateme(myform) {
> alert(myform.name);
> if (myform.mytextarea.value == '') {
> alert('textarea is empty!');
> return false;
> } else {
> return true;
> }
> }
>
> //-->
> </SCRIPT>
>
> </head>
>
> <body>
>
> <cfform action="foo.cfm" onsubmit="return validateme(this);">
>
> <textarea name="mytextarea"></textarea>
>
> <br>
>
> <input type="submit">
>
> </cfform>
>
> </body>
> </html>
>
> Dave Watts, CTO, Fig Leaf Software
That doesn't work if you include a <cfinput> field like Paul originally
asked. I just tested (see http://hksi.net/test-cfform.cfm) on CF4.5.1, and
CF just writes the "return validateme(this)" at the end of it's
auto-generated script that is triggered by the onsubmit event. The reference
to "this", in that case, has no meaning to the script, and passes validation
even with no value in IE5 SP1. To get the combo to work in this case,
replace the self-referential "this" with the fully-qualified
"document.forms[0].mytextarea", or with "_CF_this", which the CF script will
recognize as a valid reference.
Just goes to show you that even if you use CF's auto-generating JavaScript
features, you should learn to at least read JS and double-check what it
outputs. And if you're mixing CF JS with your own, be prepared to re-code
when future versions of CF potentially change their behavior or
nomenclature.
Ron Allen Hornbaker
President/CTO
Humankind Systems, Inc.
http://humankindsystems.com
mailto:[EMAIL PROTECTED]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists