Calculated value (Sum) of 2 fields populating (total)

gotpowr 18 Oct, 2024

In CF7  I have 2 fields and I'm trying to populate a 3rd based on their values.

So on a new entry, the fields are all blank.  When the user enters a value in the fields, I want a 3rd field to show the total.

On an existing entry, the fields will be populated with the saved values.  When the user changes a value in the field, I want the total field to be updated.

I tried this with a Javascript function, but I must have messed it up somewhere.  For the life of me I can't get anything to happen.

Here's my Javascript:

Calculated value (Sum) of 2 fields populating (total) image 1

Here's the event setup I tried:

Calculated value (Sum) of 2 fields populating (total) image 2

Calculated value (Sum) of 2 fields populating (total) image 3

Calculated value (Sum) of 2 fields populating (total) image 4

Max_admin 18 Oct, 2024
Answer

I think you need the events setup at the "Total" field only, and there should be one event with both fields because you have "if any matches"

if this does not work then I think you should just write a document ready event and listen for the 2 fields "input" event, I think you are comfortable writing javascript code

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gotpowr 21 Oct, 2024

So I made this change and it doesn't appear to be working:

Calculated value (Sum) of 2 fields populating (total) image 5

I wasn't sure if I was supposed to use Reload or not? (i did try adding a reload action, but it didn't seem to work)

I'll be honest, Javascript is new to me.  If I write a Javascript function, do I remove this event?

Also, should I consider the Javascript field/action to be equivalent to <script> </script> so that I can then add anything and functions underneath?

Is there any way to troubleshoot to see what the Javascript is doing (I didn't see it in the debug).

Thanks!!!

Max_admin 21 Oct, 2024

please remove the brackets from the javascript function name at the last image, does it work ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gotpowr 21 Oct, 2024

Unfortunately no :(

Max_admin 21 Oct, 2024

try to change "changes" to "input"

which v7 version do you have installed ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gotpowr 22 Oct, 2024

Input doesn't work either :(.

Is there any way to test the java code?  To see if the problem is the trigger, or if it is the code itself?

Version: 7.0.12

So I tried something for troubleshooting.

I created an alert box within the function.  On load, and when changing field, no alert box is triggered.

I pulled the alert box outside of function but within same Javascript element.  On load it's triggered, but when changing field, it is not.

Could there be some issue with the Call Function event?

gotpowr 22 Oct, 2024
1 Likes

I think I finally figured it out.

I moved the JavaScript element all the way down (below boxes) and turned "domready" to off.

I'm not familiar with JavaScript enough and when I read the description, I assumed I needed "domready" set to On.

Do I have it setup correct?  When would I want to use "domready"?

Max_admin 22 Oct, 2024

I think with domready off is correct, the code checks for the function in the window and it may not work if the function is inside dom ready, I forgot about that 

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
You need to login to be able to post a reply.