SHARE
TWEET

TotalContacts

a guest Dec 3rd, 2012 282 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  3. <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  4.  
  5.  
  6.  
  7. <script type="text/javascript">
  8. $(document).ready(function() {
  9.  
  10. // hide the form errors
  11. $('.FormErrors').hide();
  12.        
  13. // Add up the totals by race as people enter them
  14.         $('.byrace input').blur(function () {
  15.         var sum = 0;
  16.     $('.byrace input').each(function() {
  17.         sum += Number($(this).val());
  18.     });
  19.        
  20.         //whenever it blurs change it and check totals
  21.         $('#TotalContactsByRace').val(sum);
  22.         checkTotals();
  23.        
  24. });    
  25.        
  26. // Add up the totals by ethnicity as people enter them
  27.         $('.byethnicity input').blur(function () {
  28.         var sum = 0;
  29.     $('.byethnicity input').each(function() {
  30.         sum += Number($(this).val());
  31.     });
  32.        
  33.         //whenever it blurs change it and check totals
  34.         $('#TotalContactsByEthnicity').val(sum);
  35.         checkTotals();
  36.        
  37.         });    
  38.  
  39.  
  40.  
  41. // Add up the totals by gender as people enter them    
  42.         $('.bygender input').blur(function () {
  43.         var sum = 0;
  44.     $('.bygender input').each(function() {
  45.         sum += Number($(this).val());
  46.     });
  47.        
  48.         //whenever it blurs change it and check totals
  49.         $('#TotalContactsByGender').val(sum);
  50.         checkTotals();
  51.         });    
  52.  
  53. // NOTE: there is a PreSaveAction function in the form itself that also checks this and prevents submission.
  54.         function checkTotals() {
  55.         if (($('#TotalContactsByRace').val() != $('#TotalContactsByEthnicity').val()) || ($('#TotalContactsByRace').val() !=    $('#TotalContactsByGender').val())) {
  56.         $('.FormErrors').show();
  57.         }
  58.        
  59.         else{
  60.                 $('.FormErrors').hide();
  61.         }
  62.  
  63.        
  64.         }
  65.                
  66.  
  67. });
  68.  
  69.  
  70. /*
  71. This function has to be outside of the document ready for the PreSaveAction function in the pages to "find" it. It won't get called until someone clicks the save button. So jquery should be loaded by then.
  72. */
  73.         function PreSaveExternalAction() {
  74.         if (($('#TotalContactsByRace').val() != $('#TotalContactsByEthnicity').val()) || ($('#TotalContactsByRace').val() !=                    $('#TotalContactsByGender').val())) {
  75.                                 $('.FormErrors').show();
  76.                                 return false;
  77.                                 }
  78.                                 else{
  79.                                 //if all is good, return true
  80.                                 $('.FormErrors').hide();
  81.                                 return true;
  82.                                 }
  83. }      
  84.  
  85. </script>
RAW Paste Data
Top