Field calculations based on check boxes

Community Beginner ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

Afternoon everyone,
I am working on a quotation form and there is a field for a base cost [basecostamount].

I then have 3 option fields where the customer can be quoted for extras to the unit [option1costentry], [option2costentry] & [option3costentry]

There is then a subtotal field [subtotalcost]
Using checkboxes (i have these set in the same group [option123] with differing export values [Yes1], [Yes2] & [Yes3]) I would like to be able to calcuate the subtotal of the base unit plus which ever option the customer selects.  If they then decide to change their minds and select a different option the subtotalcost will recalculate

I have this currently but i have no idea on JavaScript so im guessing as it doent work its totally incorrct

 

if (this.getField("option123").value=="Yes1") {

this.getField("subtotalcost")=(basecostamount+option1costentry);

} else if (this.getField("option123").value=="Yes2") {

this.getField("subtotalcost")=(basecostamount+option2costentry);

} else if (this.getField("option123").value=="Yes3") {

this.getField("subtotalcost")=(basecostamount+option3costentry);

}

 

Any help would be greatly appreciated again......

TOPICS
How to , JavaScript , PDF forms

Views

37

Likes

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Sep 15, 2022 Sep 15, 2022

As custom calculation script of "subtotalcost" field use this:

var total = Number(this.getField("basecostamount").value);
for(var i=1; i<=3; i++){
if(this.getField("option123").valueAsString == "Yes"+i)
total += Number(this.getField("option"+i+"costentry").value);}
event.value = total;

Likes

Translate

Translate
Community Expert ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

Set the value of the field:

this.getField("subtotalcost").value = ...

Likes

Translate

Translate

Report

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 ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

As custom calculation script of "subtotalcost" field use this:

var total = Number(this.getField("basecostamount").value);
for(var i=1; i<=3; i++){
if(this.getField("option123").valueAsString == "Yes"+i)
total += Number(this.getField("option"+i+"costentry").value);}
event.value = total;

Likes

Translate

Translate

Report

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 Beginner ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied

LATEST

Thank you so much Nesa,

That worked perfectly

Likes

Translate

Translate

Report

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