admin管理员组

文章数量:1403364

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

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

Share Improve this question asked Feb 2, 2009 at 16:56 Jason SlackJason Slack
Add a ment  | 

4 Answers 4

Reset to default 6

You need

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

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

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

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

very simple to do tons of example on jquery.

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 mitting 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.

本文标签: coldfusionJavaScript on Form SubmitStack Overflow