Advertisement
Guest User

Javascript

a guest
Dec 7th, 2012
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //hide the second, third and fourth steps from the user.
  2. $("document").ready(function(){
  3.    
  4.     //Hide additional steps and the differences between the two steps if they have Javascript
  5.     function hideSteps() {
  6.         //hide the divs
  7.         $("#step1").hide();
  8.         $("#step2").hide();
  9.         $("#step3").hide();
  10.         $("#step4").hide();
  11.         $("#makingAOneTimeGift").hide();
  12.         $("#makingARecurringGift").hide();
  13.     }
  14.     //Show the submit buttons since we're going to take them through the steps
  15.     function showSubmitSteps() {
  16.         $("#submit_first").show();
  17.         $("#submit_second").show();
  18.         $("#submit_third").show();
  19.         $("#return_question").show();
  20.         $("#return_first").show();
  21.         $("#return_second").show();
  22.         $("#return_third").show();
  23.     }
  24.  
  25.     function replaceRecurringDonationValue() {
  26.         //make our variables so we don't forget
  27.         var perDonationValue = 0;
  28.         var numberOfMonths = 0;
  29.         var TotalRecurringDonationValue = 0;
  30.  
  31.         //give them their correct values
  32.         perDonationValue = $("#recurringDonationValue").val();
  33.         numberOfMonths = $("#numberOfMonths").val();
  34.  
  35.         //ensure that the maximum number of months is enforced.
  36.         if(numberOfMonths > 60) {
  37.             alert("Donations can last for a maximum of 60 months.");
  38.             $("#numberOfMonths").val(60);
  39.         }
  40.  
  41.         TotalRecurringDonationValue = perDonationValue * numberOfMonths;
  42.  
  43.         $("#TotalRecurringDonationValue").val(TotalRecurringDonationValue);
  44.     }
  45.  
  46.     function replaceDonationAmount() {
  47.         //check which they used
  48.         var donationAmount = 0;
  49.         var OneTimeDonation = $("[name=oneTimeDonationValue]").val();
  50.         var RecurringDonation = $("[name=RecurringDonationValue]").val();
  51.  
  52.         if(OneTimeDonation != 0) {
  53.             donationAmount = OneTimeDonation;
  54.         } else {
  55.             donationAmount = RecurringDonation;
  56.         }
  57.         $("#showTotalDonationAmount").text(donationAmount);
  58.        
  59.     }
  60.  
  61.     //Let's add the ability to show and hide fields via the checkboxes
  62.     function addInteractiveFields() {
  63.         //Class Year Dropdown
  64.         $("#ifClassScholashipsSelected").css("display","none");
  65.         $(".enableClassYearSelection").click(function(){
  66.             if ($("input[name=Class_Scholarships]:checked").val() == "class_scholarships") {
  67.                 $("#ifClassScholashipsSelected").slideToggle("fast"); //Slide Down Effect
  68.             } else {
  69.                 $("#ifClassScholashipsSelected").slideToggle("fast");  //Slide Up Effect
  70.             }
  71.      });
  72.      //Other Funds Dropdown
  73.         $("#ifOtherFundsSelected").css("display","none");
  74.         $(".enableOtherFunds").click(function(){
  75.             if ($('input[name=OtherFunds]:checked').val() == "other_funds" ) {
  76.                 $("#ifOtherFundsSelected").slideDown("fast"); //Slide Down Effect
  77.             } else {
  78.                 $("#ifOtherFundsSelected").slideUp("fast");  //Slide Up Effect
  79.             }
  80.      });
  81.      //In Memory Of Dropdown
  82.         $("#ifInMemoryOfSelected").css("display","none");
  83.         $(".enableInMemoryOf").click(function(){
  84.         if ($('input[name=InMemoryOf]:checked').val() == "in_memory_of" ) {
  85.             $("#ifInMemoryOfSelected").slideDown("fast"); //Slide Down Effect
  86.         } else {
  87.             $("#ifInMemoryOfSelected").slideUp("fast");  //Slide Up Effect
  88.         }
  89.      });
  90.         //In Honor Of Dropdown
  91.         $("#ifInHonorOfSelected").css("display","none");
  92.         $(".enableInHonorOf").click(function(){
  93.         if ($('input[name=InHonorOf]:checked').val() == "in_honor_of" ) {
  94.             $("#ifInHonorOfSelected").slideDown("fast"); //Slide Down Effect
  95.         } else {
  96.             $("#ifInHonorOfSelected").slideUp("fast");  //Slide Up Effect
  97.         }
  98.      });
  99.     }
  100.    
  101.     hideSteps();
  102.     showSubmitSteps();
  103.     addInteractiveFields();
  104.  
  105.     $("#recurringDonationValue").change(replaceRecurringDonationValue());
  106.     $("#numberOfMonths").change(replaceRecurringDonationValue());
  107.  
  108.     //they chose a one-time gift
  109.     $("#oneTimeGift").click(function() {
  110.         $("#makingAOneTimeGift").show();
  111.         $("#typeOfGift").text("one-time");
  112.         $("#step0").slideToggle("slow");
  113.         $("#step1").slideToggle("slow");
  114.         return false; // prevent the link from submitting
  115.     });
  116.      $("#recurringGift").click(function() {
  117.         $("#makingARecurringGift").show();
  118.         $("#typeOfGift").text("total recurring");
  119.         $("#step0").slideToggle("slow");
  120.         $("#step1").slideToggle("slow");
  121.         return false; // prevent the link from submitting
  122.     });
  123.     //let's add the "Next" buttons to make this move forward
  124.     $("#submit_first").click(function() {
  125.         $("#step1").slideToggle("slow");
  126.         $("#step2").slideToggle("slow");
  127.         replaceDonationAmount();
  128.         return false; // prevent the link from submitting
  129.     });
  130.     $("#submit_second").click(function() {
  131.         $("#step2").slideToggle("slow");
  132.         $("#step3").slideToggle("slow");
  133.         replaceDonationAmount();
  134.         return false;
  135.     });
  136.     //let's add the "Previous" button
  137.     $("#return_question").click(function() {
  138.         $("#step1").slideToggle("slow");
  139.         $("#step0").slideToggle("slow");
  140.         $("#makingARecurringGift").hide();
  141.         $("#makingAOneTimeGift").hide();
  142.         return false;
  143.     });
  144.     $("#return_first").click(function() {
  145.         $("#step2").slideToggle("slow");
  146.         $("#step1").slideToggle("slow");
  147.         return false;
  148.     });
  149.     $("#submit_third").click(function() {
  150.         $("#step3").slideToggle("slow");
  151.         $("#step4").slideToggle("slow");
  152.         return false;
  153.     });
  154.     $("#return_second").click(function() {
  155.         $("#step3").slideToggle("slow");
  156.         $("#step2").slideToggle("slow");
  157.         return false;
  158.     });
  159.     $("#return_third").click(function() {
  160.         $("#step4").slideToggle("slow");
  161.         $("#step3").slideToggle("slow");
  162.         return false;
  163.     });
  164.     $("#submit_form").click(function() {
  165.         return true; //submit the form using ajax!
  166.     });
  167. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement