PayPal parameter validation


/ Published in: JavaScript
Save to your folder(s)

This demonstrates how to validate parameters prior to submitting a PayPal form


Copy this code and paste it in your HTML
  1. <form name="FormRecuring" action="https://www.paypal.com/cgi-bin/webscr" method="post">
  2. ...
  3. <script type="text/javascript">
  4. // Validate dollar amount upon clicking Submit2.
  5. // if validation is successful, perform a 'submit' on the form.
  6. function SubmitRecuring()
  7. {
  8. // See if there's a leading '$'.
  9. if ( FormRecuring.a3.value[0]=="$" )
  10. {
  11. var iLen = FormRecuring.a3.value.length;
  12. // Strip the leading char.
  13. FormRecuring.a3.value = String(FormRecuring.a3.value).substring(1);
  14. }
  15.  
  16. var DollarAmount = parseFloat(FormRecuring.a3.value); // Convert to a float.
  17. DollarAmount = DollarAmount.toFixed(2); // keep 2 digits to the right of the decimal.
  18. // alert( DollarAmount );
  19.  
  20. if ( DollarAmount <= 0 || isNaN(DollarAmount) )
  21. {
  22. alert( "Enter a dollar amount" );
  23. return false; // return without submitting the form.
  24. }
  25. FormRecuring.submit(); // Submit the form.
  26. return true;
  27. }
  28. </script>
  29. <!-- Comment-out this input control; replace 'input' with 'img' and add 'onclick=' to call SubmitRecuring().
  30. <!-- input ilo-full-src="http://images.paypal.com/images/x-click-but31.gif" name="submit" src="giving00_files/x-click-but31.gif" alt="Make payments with PayPal, it's fast, free, and secure!" border="0" type="image" width="72" height="32"-->
  31. <img onclick="SubmitRecuring()" ilo-full-src="http://images.paypal.com/images/x-click-but31.gif" name="Submit2" src="giving00_files/x-click-but31.gif" alt="Make payments with PayPal, it's fast, free, and secure!" border="0" type="image" width="72" height="32">
  32. </form>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.