> > > I'm trying to develop a javascript validation for a 
> > > textarea. I'm getting an error message which says 
> > > "ProgramDescription.value" is not an object.
> > > 
> > > ===========
> > > 
> > > <script language="javascript1.2">
> > > function validate(testform) {
> > > if (testform.ProgramDescription.value == " ") {
> > > window.alert("Please add a program description.");
> > > return false;
> > > }
> > > return true;
> > > 
> > > }
> > > </script>
> > > 
> > > <cfform action="AddNewProgram.cfm" method="post" ONSUBMIT="return
> > > validate(this)">
> > > 
> > > <textarea name="ProgramDescription"  value="" cols="30" rows="10"
> > > wrap="virtual"></textarea>
> > > 
> > > <input type="submit"  value="submit">
> > > </cfform>
...
> I found out that you can't really combine the ColdFusion form 
> validation of <cfinput> with other javascripts validation. I 
> mean there is not built in <textarea> CF validation. So I used 
> an independent javascript validation for the textarea along 
> with the CF built in validation and the independent javascript 
> validating the <textarea> does not work. Probably has to do with
> CF assigning another name to the form.
> 
> How do you validate a <textarea> with javascript along with 
> using the built in CF javascript validation with other form 
> elements?

You can do this by simply writing a JavaScript function that validates your
field and returns true or false as appropriate, then reference that function
in your CFFORM tag's ONSUBMIT attribute, as your original code sample does.
You don't need to specify a NAME attribute for your CFFORM tag; CF will do
this automatically for you (the default name will be "CFForm_1", I think). 

There are two problems with your original code sample. One is that you've
specified a VALUE attribute for your TEXTAREA, but that's not how the
TEXTAREA tag works. Here's an example:

<textarea name="foo">This string is the value</textarea>

The other problem is that the ONSUBMIT attribute of CFFORM doesn't work the
same way as it would for an HTML form. When CF sees that, it takes the
string value you've specified and writes it into a wrapper function, which
gets created automatically by CFFORM. This wrapper function is what CFFORM
uses to call all of its own validation routines, and it will be in the
document head. It'll look like this:

<script LANGUAGE=JAVASCRIPT TYPE="text/javascript" >

<!--

function  _CF_checkCFForm_1(_CF_this)

    {

return validate(testform);

    return true;

    }


//-->

</script>

Of course, at this point the problem should be obvious. The "this" keyword
that you were expecting to reference the form won't be used inside this
wrapper function. To avoid this problem, simply use an explicit reference
within your validation function:

if (document.forms[0].ProgramDescription.value == "") ...

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444
------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to