Calculate multiple fields

  • Ckeyboard1
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 18
  • Thank you received: 0

Ckeyboard1 replied the topic: Calculate multiple fields

Ok, i got it working. But what do I to add multiples? Like this on adds but this one subtracts and so on and so forth?
#233622
  • Posts: 2147
  • Karma: 75
  • Thank you received: 277

mihaela replied the topic: Calculate multiple fields

Hello,

Please explain a bit more how this is supposed to work.

If you mean that you will have more fields where will be entered values that should be added, for example, to "InitialCostValue" the code would look similar to this:
ff_getElementByName('CurrentCostValue').value =
Number(ff_getElementByName('InitialCostValue').value) +
Number(ff_getElementByName('TotalIncrease1').value) +
Number(ff_getElementByName('TotalIncrease2').value);

Let me know whether this is what you wanted to know.

Regards,

Mihaela
#233642
  • Ckeyboard1
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 18
  • Thank you received: 0

Ckeyboard1 replied the topic: Calculate multiple fields

Hi, I've played with the code a bit, bit there is still a lot that I am missing. So I'll do my best to explain what it is they want me to do to make this work, but it's very complicated.

So this is an electronic form that has to calculate multiple times and they will add these calculations over time. I'm going to include screen shots to give you a visual. Hope those help.

1. So the user puts in a value in a field that I have named "InitialCostValue" I need this field to immediately show in a Total field I have named "CurrentCostValue". In otherwords, user puts in a number and it pops up in the CurrentCostValue Field. (See screenshot attached)


2. Then, they will add Mods (Modifications to Contracts) which will either increase or Decrease the value of the Current Cost Field. But it's optional. The cost may go up or down or nothing at all. I have this setup with a radio group. the option to add a Mod or not. They wanted this because the form is already way long so i did visibility code to hide these fields until they click on Add Mod. See screenshot 2.

3. Next to make things even more difficult, They don't want the fields to show to increase or decrease the Current Cost Value. So had to add radio buttons with Visibility code here as well. See screen Shot 3.

4. After choosing to increase or decrease, Screenshot 4, you enter a value. This value you enter here either adds or subtracts from the "IntitialCostValue" and then should populate the "CurrentCostField". Sounds easy enough but wait there's more.

5. Here is the part that I had to consider Suicide as an option. Because they want to add MULTIPLE mods with calculations. Look at the bottom of screen shot 4 and you'll see a radio button that says "Add Mod" again. Yep! How many of these Mods do they want me to add? 50! Yep no joke %) with visibility code and calculations to add or subtract for each one. So now here is what it looks like.

Initial Cost
+ or -
Increase or Decrease (MOD 1)
=
Current Cost

OR

Initial Cost
+ or -
Increase or Decrease (MOD 1)
Increase or Decrease (MOD 2)
=
Current Cost

OR

Initial Cost
+ or -
Increase or Decrease (MOD 1)
Increase or Decrease (MOD 2)
Increase or Decrease (MOD 3)
=
Current Cost

and so on all the way to 50

I am at a lose at this point. I have done what you said with the if else statements and got it to work BUT the Current Cost Filed has to do these calculations each time you add a mod. Is there a way to Export my form and send it to you so you can take a look at it? an Email address or something?

Thank you very much for your help!
#233722
Attachments:
  • Posts: 2147
  • Karma: 75
  • Thank you received: 277

mihaela replied the topic: Calculate multiple fields

Hello,

Thank you for the detailed explanation. I understand now how this should work so there is no need for you to send me the form, since setting all this to work on your form would be out of scope of our support.

Either way, I can give you guidelines how to make this work.

You can create a section with radio group to choose to Increase or Decrease, two fields to enter a value for which the 'InitialCostValue' should be increased or decreased and an option to add another MOD.

Then you could copy this section 50 times and give fields name as follows: "increaseDecreaseNO", "TotalIncreaseNO", "TotalDecreaseNO" and "Add modeNO" where no would be numbers from 1 to 50.

Then you could go through all fields with a for (i = 0; i <= 50; i++) loop, similar as in this example: crosstec.org/en/forums/1-forums/121907-t...html?start=12#214933 .

Furthermore, to avoid having to put the calculation code in Actionscript for each element, you could put the whole calculation code in the Initialization script as in the example above .
Here is another example with code in Initialization script crosstec.org/en/forums/3-breezingforms-f...-results.html#228275 .

I hope that this will help you and that you will manage to make this work as you wanted.
If you have more questions regarding this, feel free to ask.

Regards,

Mihaela
#233745
  • Ckeyboard1
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 18
  • Thank you received: 0

Ckeyboard1 replied the topic: Calculate multiple fields

Let me ask you this? If I put in code to add MOD1 and MOD2 then it come out fine. BUT if I increase MOD1 and Decrease Mod2 it messes up. What would the code look like to Increase MOD1 and then Decrease Mod2? I'm lost.
#233814
  • Posts: 2147
  • Karma: 75
  • Thank you received: 277

mihaela replied the topic: Calculate multiple fields

Hello again,

You need to add a check to see what is selected in radiogroup(increase or decrease) in each MOD to know whetehr you have to increase or decrease the value in order for this to work properly.
var currvalue= ff_getElementByName('InitialCostValue').value;
for (i = 1; i <= 50; i++) {
if(jQuery('[name="ff_nm_increaseDecrease' + i + '[]"]:checked').val() == "Increase") {
currvalue =
Number(currvalue) +
Number(ff_getElementByName('TotalIncrease'+i).value);
}
else if(jQuery('[name="ff_nm_increaseDecrease' + i + '[]"]:checked').val() == "Decrease") {
currvalue =
Number(currvalue)-
Number(ff_getElementByName('TotalDecrease'+i).value);
}

}
ff_getElementByName('CurrentCostValue').value = currvalue;

Let me know whether you've managed to write this to work for your form.

Regards,

Mihaela
#233844
Moderators: ForumSupporttomeperica
Time to create page: 0.057 seconds

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99€

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here