Posted By

ryarwood on 06/25/11


Tagged

javascript CALCULATION registration addition pcrf


Versions (?)

Registration Form Calculation


 / Published in: JavaScript
 

URL: http://pcrf-kids.org/carew/registration.html

  1. function dp(price) // Form:group - Totals Script //
  2. {
  3. string = "" + price;
  4. number = string.length - string.indexOf('.');
  5. if (string.indexOf('.') == -1)
  6. return string;
  7. if (number == 1)
  8. return string;
  9. if (number == 2)
  10. return string;
  11. if (number > 3)
  12. return string.substring(0,string.length-number+3);
  13. return string;
  14. }
  15.  
  16. function calculate()
  17. {
  18. document.forms.onlinereg.elements["presentingTotal"].value = dp((document.forms.onlinereg.elements["presentingPrice"].value)*(document.forms.onlinereg.elements["presentingNum"].value));
  19. document.forms.onlinereg.elements["titleTotal"].value = dp((document.forms.onlinereg.elements["titlePrice"].value)*(document.forms.onlinereg.elements["titleNum"].value));
  20. document.forms.onlinereg.elements["classicTotal"].value = dp((document.forms.onlinereg.elements["classicPrice"].value)*(document.forms.onlinereg.elements["classicNum"].value));
  21. document.forms.onlinereg.elements["corpTotal"].value = dp((document.forms.onlinereg.elements["corpPrice"].value)*(document.forms.onlinereg.elements["corpNum"].value));
  22. document.forms.onlinereg.elements["golferTotal"].value = dp((document.forms.onlinereg.elements["golferPrice"].value)*(document.forms.onlinereg.elements["golferNum"].value));
  23. //document.forms.onlinereg.elements["golfDinnerTotal"].value = dp((document.forms.onlinereg.elements["golfDinnerPrice"].value)*(document.forms.onlinereg.elements["golfDinnerNum"].value));
  24. document.forms.onlinereg.elements["publicDinnerTotal"].value = dp((document.forms.onlinereg.elements["publicDinnerPrice"].value)*(document.forms.onlinereg.elements["publicDinnerNum"].value));
  25. document.forms.onlinereg.elements["donationTotal"].value = dp((document.forms.onlinereg.elements["donationPrice"].value)*(document.forms.onlinereg.elements["donationNum"].value));
  26. document.forms.onlinereg.elements["grandTotal"].value = dp(eval(document.forms.onlinereg.elements["titleTotal"].value) + eval(document.forms.onlinereg.elements["classicTotal"].value) + eval(document.forms.onlinereg.elements["corpTotal"].value) + eval(document.forms.onlinereg.elements["golferTotal"].value) + eval(document.forms.onlinereg.elements["publicDinnerTotal"].value) + eval(document.forms.onlinereg.elements["presentingTotal"].value) + eval(document.forms.onlinereg.elements["donationTotal"].value));
  27. }
  28.  
  29. function creditChange() {
  30. document.onlinereg.creditChangeNum.value = "yes";
  31. }
  32.  
  33. function MM_validateForm() { //v4.0
  34.  
  35. if (document.getElementById){
  36. var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  37.  
  38. if (document.onlinereg.grandTotal.value == "0") {
  39. errors+='- Please select a sponsorship level.\n';
  40. }
  41.  
  42. for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
  43. if (val) { nm=val.alt; if ((val=val.value)!="") {
  44. if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
  45. if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
  46. } else if (test!='R') { num = parseFloat(val);
  47. if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
  48. if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
  49. min=test.substring(8,p); max=test.substring(p+1);
  50. if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
  51. } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  52. } if (errors) alert('The following error(s) occurred:\n'+errors);
  53. document.MM_returnValue = (errors == '');
  54. } }

Report this snippet  

You need to login to post a comment.