tags:

views:

998

answers:

2

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"&gt;&lt;/script&gt;
  <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"&gt;&lt;/script&gt;
<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>
A: 

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.

Mike Robinson
+1  A: 

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.

Nealv