Reputation:
I am setting up validation following the tutorial at link text
My form action script is as follows:
<form method="POST" action="formproc_to_paypal.php" id="example"
target="_self" onsubmit="CalcAmount (this); ReadForm(this);" name="example">
When I remove/change the action line to "" (as the tutorial shows) the validation works fine. Any idea why the action is causing it not to validate?
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
<style type="text/css">
label { width: 10em; float: left; }
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
p { clear: both; }
.submit { margin-left: 12em; }
em { font-weight: bold; padding-right: 1em; vertical-align: top; }
</style>
<script>
$(document).ready(function(){
$("#example").validate();
});
</script>
Upvotes: 0
Views: 2328
Reputation: 6884
Be sure to do a return false after every javascript call, otherwise when the javascript is done, the is submitted to the action.
that is also why it works if there is no action specified.
Upvotes: 1
Reputation: 25159
Something like this
function validate(form){
return(CalcAmount (form) && ReadForm(form));
}
Keep in mind this a very quick implementation, you might have to add some more details. The general idea is have one function that returns a single boolean based on a combination of results.
Upvotes: 0