Skip to main content
Inspiring
October 9, 2023
Answered

Calculating the total of linked Checkboxes and numeric text fields

  • October 9, 2023
  • 2 replies
  • 4149 views

Hi all.

I am very new at this but I am in desperate need of help. I am creating an Adobe form where I want to calculate the money value in a text field that is only calculated when the checkbox is ticked. I have come up with this code to do it and it is kind of working but not 100%. 

 

event.value = 0;

if (this.getField("SCB1").value != "Off")
event.value+= (this.getField("S1").value);

 

if (this.getField("SCB2").value != "Off")
event.value+= (this.getField("S2").value);

 

if (this.getField("SCB3").value != "Off")
event.value+= (this.getField("S3").value);

 

SCB1 is Checkbox 1 and S1 is the text field

 

I was so excited that this was working until I started adding more SCBs linked to Ss. Instead of creating a running total in the subtotal text field, it is doing something weird. When I check SCB1 with '50.00' in S1, the total show '50.00' but when I add a check to SCB2 with '50.00' in S2, the total shows '5050.00'.

This is literally my first code that I am writing and I don't know how to fix it. If you can help within the next day or two, it would be a huge help!

    Correct answer Nesa Nurani

    Hi Nesa,

    You have been a huge help but I have just one last challenge and I have tried to find the solution for the last couple of hours (again). 

     

    I have 3 dropdown boxes with export values added to the selections. I would like to select an item in each DB and have the export value added together and populate a text field. I can do this with a simple 'sum' calculation but I would like the text field to be empty, not with '0", when the option - select - is selected in the box.

     

    I also want to do this for the two DBs as one is the item (with export value price) and the other is the number of items they want (multiplier). Again, the simple product function works but I would like - Select - to leave the text field empty, not with a '0".

     

    Is there a way to do this? 


    In text field, go to 'Validate' tab and enter this script:

    if(event.value == 0) event.value = "";

    2 replies

    Nesa Nurani
    Community Expert
    October 9, 2023

    Use this:

    var total = 0;
    for(var i=1; i<=3; i++){
    if(this.getField("SCB"+i).valueAsString !== "Off")
    total += Number(this.getField("S"+i).valueAsString);}
    event.value = total;

    If you add more fields, just replace '3' with the number of fields you have.

    Inspiring
    October 10, 2023

    Thanks for this. I am having trouble using this in another text field. It worked for the first two text fields (Subtotal A and B) but it is not working for C. I changed 'SCB' to 'LCB' and 'S' to 'L', which worked but when I did it for 'VCB' and 'V', it didn't work. Would I have to change the names of those boxes for it to work or am I doing something wrong?

    Nesa Nurani
    Nesa NuraniCorrect answer
    Community Expert
    October 10, 2023

    Hi Nesa,

    You have been a huge help but I have just one last challenge and I have tried to find the solution for the last couple of hours (again). 

     

    I have 3 dropdown boxes with export values added to the selections. I would like to select an item in each DB and have the export value added together and populate a text field. I can do this with a simple 'sum' calculation but I would like the text field to be empty, not with '0", when the option - select - is selected in the box.

     

    I also want to do this for the two DBs as one is the item (with export value price) and the other is the number of items they want (multiplier). Again, the simple product function works but I would like - Select - to leave the text field empty, not with a '0".

     

    Is there a way to do this? 


    In text field, go to 'Validate' tab and enter this script:

    if(event.value == 0) event.value = "";

    kglad
    Community Expert
    October 9, 2023

    in the future, to find the best place to post your message, use the list here, https://community.adobe.com/

    p.s. i don't think the adobe website, and forums in particular, are easy to navigate, so don't spend a lot of time searching that forum list. do your best and we'll move the post (like this one has already been moved) if it helps you get responses.



    <"moved from using the community">

     

    Inspiring
    October 9, 2023

    Thanks heaps. First time poster so I have not clue where to post it. Hoping for answers in the next day so thank you for moving it for me. 

    kglad
    Community Expert
    October 9, 2023

    the acrobat forum is the best place for acrobat questions.