Calculating Checkbox Sum

  • Eddy.vh
  • Eddy.vh's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 74
  • Thank you received: 7

Eddy.vh created the topic: Calculating Checkbox Sum

Hello.

On the attached form, I have a calculation that is carried out according to checkboxes.
Everything works well.
I insert visibility rules to display a checkbox as an option.
If this box is clicked, its value is added well.
If I hide this box with the "show - disabled" radio, I would like its value to be canceled in the amountowing field and the box to be unchecked.
For the check mark, in the visibility rules, I wrote: if element xxx is off set xxx! Empty - This clears the box well but does not cancel its value in the calculated field.

How to do ?

An example form is attached.

Thanks for your help.

You do not have permissions to access this page.
#232101
  • Posts: 1465
  • Karma: 48
  • Thank you received: 194

mihaela replied the topic: Calculating Checkbox Sum

Hello,

I understand what you want to achieve.

Your form didn't get attached. Please create a package from your form, ZIP it and send it zipped as an attachment.
Then I will give you instructions how to make this work for your form.

Regards,

Mihaela
#232106
  • Eddy.vh
  • Eddy.vh's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 74
  • Thank you received: 7

Eddy.vh replied the topic: Calculating Checkbox Sum

Hi Mihaela.

The attachment had been added yesterday, I do not understand ...
Revoici therefore a very small form (it is not the form that will be really used, it is too long).

Thank you for your help.

File Attachment:

File Name: calculatin...1-22.zip
File Size:8 KB
#232121
Attachments:
  • Posts: 1465
  • Karma: 48
  • Thank you received: 194

mihaela replied the topic: Calculating Checkbox Sum

Hello again,

I'm not sure why the attachment isn't there anymore then. But the important thing is that it is here now.

There are two ways how you could resolve this:

First way is that you put all the calculation code in the Initialization script.
Navigate to your form's Advanced options > More options > Scripts and in the Initialization script section set Type to Custom.

In the code area below put code similar to this:
function ff_formname_init()
{   setInterval(calc, 500);
} // ff_formname_init

function calc() {
     ff_getElementByName('amountowing').value=220;

    if (ff_getElementByName('check1').checked) {
         ff_getElementByName('amountowing').value =
         Number(ff_getElementByName('amountowing').value) + Number(ff_getElementByName('check1').value);
    }
    
     if(ff_getElementByName('check2').checked) {
        ff_getElementByName('amountowing').value =
        Number(ff_getElementByName('amountowing').value) + Number(ff_getElementByName('check2').value);
    }

}
This would resolve the problem since calc() function would be called every half second. Since box is properly cleared on setting "show" to "disabled" next time calc() would be run it wouldn't add check2 to the sum.

Other way would be to create Actionscript for show radio group.
You could add Actionscript like this:
function ff_show_action(element, action)
{
    ff_amountowing_action(element,action);
} // ff_show_action
NOTE: Set Action to Change.
That way calculation function would be called when "show" value is changed which would resolve the issue because it wouldn't add check2 to the sum if it is set to disabled because check2 wouldn't be checked anymore.

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

Regards,

Mihaela
#232122
The following user(s) said Thank You: Eddy.vh
  • Eddy.vh
  • Eddy.vh's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 74
  • Thank you received: 7

Eddy.vh replied the topic: Calculating Checkbox Sum

Mihaela.

Why did not I think about it? It's so logical when I read you! :)
The second solution seems easier to implement for the interested person and managing his form.

I thank you very much for your precious help.
#232123
  • Eddy.vh
  • Eddy.vh's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 74
  • Thank you received: 7

Eddy.vh replied the topic: Calculating Checkbox Sum

My last message would not be validated?

Mihaela,

Why did not I think, it's so obvious;)
I thank you for this solution and your precious help.
#232145
Moderators: ForumSupporttomeperica
Time to create page: 0.076 seconds

New Support System

Dear Customers,

Users with active subscription have support priority which will be dona via ServiceDesk (My Account > Raise a ticket).
FREE Support topics will be answered when AND if there is time.

You can check support guidelines here : here

Regards,
Crosstec Team

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