Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I validate a textarea type field within a CFFORM? 2

Status
Not open for further replies.

joannyk

Programmer
Jan 16, 2001
18
HK
Dear All,

I have defined this :-

<textarea name=&quot;message&quot; rows=&quot;5&quot; cols=&quot;70&quot; ></textarea>

within a <CFFORM></CFFORM> tag.

And I have defined a javascript funcion validate_message() to validate this field. However, I don't know where to call this javascript to execute when submitting the form.

Many Thanks if you can help !!!

Regards,
Joan
 
I think this should work for you.

<cfform method=&quot;post&quot; action=&quot;MyScript.cfm&quot; onsubmit=&quot;validate_message()&quot;>

Let me know if you have any problems.
GJ
 
Hi GunJack!

Thanks for your solution. I've tried this out but it didn't execute the javascript at all. I know ColdFusion will generate javascript such as &quot;_CF_checkCFForm_1()&quot; which will proceed the validation for CF tag field only. Since textarea doesn't belong to CF so I think I need to write another javascript explicitly. Or I can embed the code inside the &quot;_CF_checkCFForm_1()&quot; function to make it effect?
 
Hey Joan,

I don't use <cfform> and the built in error handling but I don't see why it wouldn't work if you can embed your code in the automatic function. I believe I did test the code above and it worked as I remember. If you want to post your <cfform> tag and the javascript function, I can check it out but I didn't have any trouble with it executing. You might just have a simple syntax error.

GJ
 
I have found it easier to stay away from the <cfform> tag altogether - especially when wanting to utilize JS validations on fields.... Just use a normal <form> tag as you would in HTML. If you need to use any #variable.values# from your .cfm file, put <cfoutput> tags around your <textarea>.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top