Client Side Calculation
Last Post 10-12-2012 06:19 AM by Ryan Bakerink. 7 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
BrettUser is Offline
wading in the water
wading in the water
Posts:22
Avatar

--
10-11-2012 05:42 AM
    I have a form that performs a calculation on several fields and then places the total in another field. This is what I have as the client side event and it works great: var Children = $(childrenParticipating); var Adults = $(adultsParticipating); var Hours = $(hoursServed); $(totalHoursGiven) = ((Children * 1) + (Adults * 1)) * (Hours * 1); There are some instances where this calculation needs to be overridden and the total entered manually. Can this be done?
    Ryan BakerinkUser is Offline
    river guide
    river guide
    Posts:1900
    Avatar

    --
    10-11-2012 08:37 AM
    Hello Brett,

    So here's your calculation:

    var Children = $(childrenParticipating); var Adults = $(adultsParticipating); var Hours = $(hoursServed); $(totalHoursGiven) = ((Children * 1) + (Adults * 1)) * (Hours * 1);

    If you need to perform a different calculation based on a certain condition, then program the condition using JavaScript, like the example below:

    var one = 'True';

    if(one == 'True')
    {
    var Children = $(childrenParticipating); var Adults = $(adultsParticipating); var Hours = $(hoursServed); $(totalHoursGiven) = ((Children * 1) + (Adults * 1)) * (Hours * 1);
    }
    else
    {
    var Children = // Different Calculation here
    }


    Just keep in mind, that you can separate calculations by using if, else if, and else statements in JavaScript. Whenever the time to override the calculation, make sure you have a condition in place.

    Please let me know if you have any questions.

    Thanks,

    Ryan
    BrettUser is Offline
    wading in the water
    wading in the water
    Posts:22
    Avatar

    --
    10-11-2012 11:10 AM
    Thanks for the reply Ryan.

    The calculation itself works fine:
    var Children = $(childrenParticipating);
    var Adults = $(adultsParticipating);
    var Hours = $(hoursServed);
    $(totalHoursGiven) = ((Children * 1) + (Adults * 1)) * (Hours * 1);

    I would like to be able to type a new number into the totalHoursGiven field after the calculation has been performed. I don't see how this can be done with an if then statement though.




    Ryan BakerinkUser is Offline
    river guide
    river guide
    Posts:1900
    Avatar

    --
    10-11-2012 12:02 PM
    Hello Brett,

    I don't feel as though your providing enough specific details.

    What does "Being able to type a new number into the totalHoursGiven field" mean to you?? I don't entirely understand what your question means.

    Is there a field on your form called totalHoursGiven? And after the Calculation on this field occurs, you'd like to be able to change the number of hours?

    Please provide as many useful details as possible.

    Thanks,

    Ryan
    BrettUser is Offline
    wading in the water
    wading in the water
    Posts:22
    Avatar

    --
    10-12-2012 05:52 AM
    Sorry about that.

    Yes exactly. There a field called totalHoursGiven where the calculation happens.

    After the Calculation on this field occurs, if I try to change the number it is automatically changed back by the calculation.

    Basically after the original calculation is made I would like to disable the calculation and override the number manually if necessary.


    Ryan BakerinkUser is Offline
    river guide
    river guide
    Posts:1900
    Avatar

    --
    10-12-2012 05:56 AM
    Hello Brett,

    I feel that you can use the following condition for your calculation:

    if($(totalHoursGiven) == '')
    {
    var Children = $(childrenParticipating);
    var Adults = $(adultsParticipating);
    var Hours = $(hoursServed);
    $(totalHoursGiven) = ((Children * 1) + (Adults * 1)) * (Hours * 1);
    }
    else
    {
    // Dont perform the calculation.
    var nothing;
    }

    Let me know if this helps or if you have any questions.

    Thanks,

    Ryan
    BrettUser is Offline
    wading in the water
    wading in the water
    Posts:22
    Avatar

    --
    10-12-2012 06:14 AM
    Ryan  -

    Thank you for your help with this! That is what I was trying to do, It works perfect.
    Ryan BakerinkUser is Offline
    river guide
    river guide
    Posts:1900
    Avatar

    --
    10-12-2012 06:19 AM
    Great to hear, glad that I could be of assistance.

    Hope you have a great weekend!

    -Ryan


    ---
  • film izle
  • 720 izle
  • film
  • sinema izle
  • film makinesi
  • T�rk�e dublaj film
  • film izle
  • film izle
  • baglan film izle
  • sinema izle
  • 1080 film izle
  • film mercegi