× Form Help

calculating fields based on different conditional fields

  • Leni14
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 84
  • Thank you received: 0

Leni14 created the topic: calculating fields based on different conditional fields

Hi there,

hope someone could help me.

I have a switcher with values on and off. If value is on field number1 is shown and if value is off field number2 is shown.

Then there is a field number3.

Depending on users' choice on switcher I want to calculate total of number3 * number 1 or number 2. I tried it with the example of the documentation, but adding number3 to the code will end up calculation only if there are values in all of the 3 fields.

Can someone give me a tip how to achieve this?

Thx,
Leni
#238957
  • Posts: 3128
  • Karma: 105
  • Thank you received: 413

mihaela replied the topic: calculating fields based on different conditional fields

Hello,

Could you please send me the code that you have used so I can see whether the error might be?

Regards,

Mihaela
#238980
  • Leni14
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 84
  • Thank you received: 0

Leni14 replied the topic: calculating fields based on different conditional fields

Thank you mihaela,

sure:

switcher is a select field:
0;Stundensatz;Stundensatz
1;Tagessatz;Tagessatz

Stundensatz is:
function ff_Stundensatz_action(element, action)
{
ff_getElementByName('netto').value =
Number(ff_getElementByName('Stundensatz').value) *
Number(ff_getElementByName('Tagessatz').value) *
Number(ff_getElementByName('Anzahl').value);
}
// ff_Stundensatz_action

Tagessatz is:
function ff_Tagessatz_action(element, action)
{
ff_getElementByName('netto').value =
Number(ff_getElementByName('Stundensatz').value) *
Number(ff_getElementByName('Tagessatz').value) *
Number(ff_getElementByName('Anzahl').value);
}
// ff_Tagessatz_action

Anzahl is:
function ff_Anzahl_action(element, action)
{
ff_getElementByName('netto').value =
Number(ff_getElementByName('Stundensatz').value) *
Number(ff_getElementByName('Tagessatz').value) *
Number(ff_getElementByName('Anzahl').value);
}
// ff_Anzahl_action

and netto is:
function ff_netto_action(element,action)
{
ff_getElementByName('netto').value = 0;
{
ff_getElementByName('netto').value =
Number(ff_getElementByName('Stundensatz').value) *
Number(ff_getElementByName('Tagessatz').value) *
Number(ff_getElementByName('Anzahl').value);
}
}
// ff_netto_action

So if switcher is set to Stundensatz it should calculate Studensatz * Anzahl = netto;
if switcher is set to Tagessatz it should calculate Tagessatz * Anzahl = netto
#238984
  • Posts: 3128
  • Karma: 105
  • Thank you received: 413

mihaela replied the topic: calculating fields based on different conditional fields

Hello,

In that case, please try using this code:
function ff_FIELDNAME_action(element, action)
{
if(ff_getElementByName('switcher').value == "Stundensatz") {
    ff_getElementByName('netto').value =
    Number(ff_getElementByName('Stundensatz').value) * Number(ff_getElementByName('Anzahl').value);
    }
else if(ff_getElementByName('switcher').value == "Tagessatz") {
    ff_getElementByName('netto').value =
    Number(ff_getElementByName('Tagessatz').value) * Number(ff_getElementByName('Anzahl').value);
    }
}
// ff_FIELDNAME_action
NOTE: In the code above, make sure to replace "switcher" with the name of the switcher select list element in your form.

Let me know whether this works as you wanted after the change.

Regards,

Mihaela
#238991
  • Leni14
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 84
  • Thank you received: 0

Leni14 replied the topic: calculating fields based on different conditional fields

Thank you Mihaela,

I changed it to your suggested code but it does the same. It's only calculation "netto" if in there are values in both fields (Tagessatz and Stundensatz).
#238992
  • Posts: 3128
  • Karma: 105
  • Thank you received: 413

mihaela replied the topic: calculating fields based on different conditional fields

Hello again,

Could you please create a package with your form as explained here crosstec.org/en/support/online-documenta...ted/94-packages.html ?

Did you change the code for all the fields included in the calculation?

I don't see why this code is not working properly.

Regards,

Mihaela
#238993
Moderators: ForumSupport
Time to create page: 0.052 seconds

We Are Doing Our Part

Massive discounts on all of our extension subscription plans to help you and your business in these times.

Get Your Subscription Here

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

News and Updates

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

All Extensions Subscription

We are doing our part and support your business with extremely low prices -- For example 6-Months-Subscription for only $9 USD. For as long as necessary.

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!