views:

208

answers:

5

Hello All,

I am submitting a ColdFusion Form and I want to run some JavaScript to check field validation before I run my ColdFusion code to process the form as needed.

How can I do this? What do I do in JS to call my .cfm file after the form passes validation?

Thanks!

-Jason

A: 

You can attach a onclick event to your input button, for example:

<input type="submit" value="Submit" onClick="validate()">

Then the validate method will be responsible for checking form values. The validate method should return true if the form is valid, thus 'committing' the form submit. If it returns false the form is not submitted. This is how it works for html, javascript and forms.

In addition, the docs linked by mark should help you further.

Miguel Ping
+1  A: 

JQuery - http://jquery.com/ validation addin for jquery - http://docs.jquery.com/Plugins/Validation

very simple to do tons of example on jquery.com

+5  A: 

You need

<form name="myform" action="myserverscript.cfm" onsubmit="return validate()">

if you return true the form submits, false it doesn't

meouw
+2  A: 

i hope you're doing the validation on the server side as well. never rely on just javascript to scrub your data.

rip747