Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
- <script type="text/javascript" src="https://www.google.com/jsapi"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- // hide the form errors
- $('.FormErrors').hide();
- // Add up the totals by race as people enter them
- $('.byrace input').blur(function () {
- var sum = 0;
- $('.byrace input').each(function() {
- sum += Number($(this).val());
- });
- //whenever it blurs change it and check totals
- $('#TotalContactsByRace').val(sum);
- checkTotals();
- });
- // Add up the totals by ethnicity as people enter them
- $('.byethnicity input').blur(function () {
- var sum = 0;
- $('.byethnicity input').each(function() {
- sum += Number($(this).val());
- });
- //whenever it blurs change it and check totals
- $('#TotalContactsByEthnicity').val(sum);
- checkTotals();
- });
- // Add up the totals by gender as people enter them
- $('.bygender input').blur(function () {
- var sum = 0;
- $('.bygender input').each(function() {
- sum += Number($(this).val());
- });
- //whenever it blurs change it and check totals
- $('#TotalContactsByGender').val(sum);
- checkTotals();
- });
- // NOTE: there is a PreSaveAction function in the form itself that also checks this and prevents submission.
- function checkTotals() {
- if (($('#TotalContactsByRace').val() != $('#TotalContactsByEthnicity').val()) || ($('#TotalContactsByRace').val() != $('#TotalContactsByGender').val())) {
- $('.FormErrors').show();
- }
- else{
- $('.FormErrors').hide();
- }
- }
- });
- /*
- 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.
- */
- function PreSaveExternalAction() {
- if (($('#TotalContactsByRace').val() != $('#TotalContactsByEthnicity').val()) || ($('#TotalContactsByRace').val() != $('#TotalContactsByGender').val())) {
- $('.FormErrors').show();
- return false;
- }
- else{
- //if all is good, return true
- $('.FormErrors').hide();
- return true;
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement