Skip to main content
Known Participant
September 15, 2022
Answered

Field calculations based on check boxes

  • September 15, 2022
  • 2 replies
  • 660 views

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......

This topic has been closed for replies.
Correct answer Nesa Nurani

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;

2 replies

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
September 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;

Known Participant
September 16, 2022

Thank you so much Nesa,

That worked perfectly

Bernd Alheit
Community Expert
Community Expert
September 15, 2022

Set the value of the field:

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