Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
4

Calculating the total of linked Checkboxes and numeric text fields

Explorer ,
Oct 09, 2023 Oct 09, 2023

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!

3.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Oct 09, 2023 Oct 09, 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.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 10, 2023 Oct 10, 2023

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

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

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 09, 2023 Oct 09, 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">

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 09, 2023 Oct 09, 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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 09, 2023 Oct 09, 2023

the acrobat forum is the best place for acrobat questions.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 09, 2023 Oct 09, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 09, 2023 Oct 09, 2023

Yes! Thank you so much! Works perfectly!

 

I have another question as well. I have tried a number of different scripts for this but none seem to be working. 

 

I want to populate a numeric value from a dropdown box selection into multiple text fields with each text field having a different number but blank if nothing is selected. The dropdown box I am using as an experiement is called 'Heatingsystem' with the items 'Gas' and 'Solar' and the text Fields are 'S1', 'L1' and 'V2'. 

 

If you can help, that would be great! 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 09, 2023 Oct 09, 2023

Use this in dropdown field as 'Validate' script and replace numbers with actual numbers you wish for those fields:

 

 

var S = this.getField("S1");
var L = this.getField("L1");
var V = this.getField("V2");

if(event.value == "Gas"){
S.value = 1;
L.value = 2;
V.value = 3;}

else if(event.value == "Solar"){
S.value = 4;
L.value = 5;
V.value = 6;}

else{
S.value = "";
L.value = "";
V.value = "";}

 

You can also use it as 'Calculate' script but then pay attention to field calculation order.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 09, 2023 Oct 09, 2023

Thanks for this but it is only kind of working. If I select 'Gas', nothing populates but if I select 'Solar', the numbers do populate in the right place. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 09, 2023 Oct 09, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 09, 2023 Oct 09, 2023

Sorry...I mean I am having trouble with the first formula as well in a third box. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 09, 2023 Oct 09, 2023

Check console for errors.

If you use script for different fields, you also need to change field names.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 09, 2023 Oct 09, 2023

I got it working. There were some gaps in the sequence of text and checkboxes and once I fixed this (by adding hidden boxes named in numbered sequence), now both scripts are working perfectly.

 

Hopefully these are the two most complicated that I need and that my boss doesn't ask for a more complicated one that might see a modification of the dropdown formula (hopefully they don't ask!). 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 10, 2023 Oct 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? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 10, 2023 Oct 10, 2023

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

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 10, 2023 Oct 10, 2023

Thanks heaps.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 14, 2023 Oct 14, 2023

Hi Nesa,

You have been a huge help but I have come across another problem that my boss has given me. 

They would like me to populate a text field from either a dropdown box OR a text field. The text field will be fillable with a number and the dropbox has values added on to the options. I have tried a number of different options again but cannot get it to work. It is complicated as the line is to be dropdown box OR ______per sqm x No. of sqm = text field total. 

 

This seems advanced stuff that is way above my head. 

I found a simply way to do it as two separate entries but my boss would like it on one line. 

Any help would be appreciated!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 14, 2023 Oct 14, 2023

The fillable box will be the no. of sqm with a fixed price in the _____ per sqm. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2023 Oct 15, 2023
LATEST

For multiplication, you can use built in option under 'Calculate' tab select Product(x) and pick your fields.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines