Skip to main content
Participating Frequently
February 4, 2025
Answered

Simple form requiring simple Javascript, tearing hair out

  • February 4, 2025
  • 1 reply
  • 405 views

I have a form with radio buttons and a total.

 

When you select certain buttons the price is totalled in a 'Total' field box..

 

There is one radio button 'Withdrawal' that if clicked, the total price in the 'total' field needs to increase by 6.9% 

I've tried adding code to 'Total' the extra 6.9% if the radio button 'Withdrawal' is selected. No Luck

I've tried adding code to ''Withdrawal' radion button to incrase the 'Total' by 6.9% if selected. No Luck

 

PDF ATTACHED!

Correct answer Nesa Nurani

Use this as custom calculation script in "Total" field, it will calculate all checkboxes and add 6.9% increase if withdrawal is checked:

var fields = [
  "MarketingPackageA",
  "MarketingPackageB",
  "MarketingPackageC",
  "Audience Maximiser",
  "Photo For Sale Sign",
  "Sunset Photoshoot",
  "Be Seen Social Media",
  "Auctioneer’s Fee",
  "Body Corporate Disclosure Statement",
  "Title Search"
];

var per = 1.069;
var total = 0;

for(var i=0; i<fields.length; i++){
 var f = this.getField(fields[i]).valueAsString;
 if(f !== "Off")
  total += Number(f);}

if(this.getField("Withdrawal").valueAsString !== "Off")
total = total*per;

event.value = total.toFixed(2);

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
February 4, 2025

Use this as custom calculation script in "Total" field, it will calculate all checkboxes and add 6.9% increase if withdrawal is checked:

var fields = [
  "MarketingPackageA",
  "MarketingPackageB",
  "MarketingPackageC",
  "Audience Maximiser",
  "Photo For Sale Sign",
  "Sunset Photoshoot",
  "Be Seen Social Media",
  "Auctioneer’s Fee",
  "Body Corporate Disclosure Statement",
  "Title Search"
];

var per = 1.069;
var total = 0;

for(var i=0; i<fields.length; i++){
 var f = this.getField(fields[i]).valueAsString;
 if(f !== "Off")
  total += Number(f);}

if(this.getField("Withdrawal").valueAsString !== "Off")
total = total*per;

event.value = total.toFixed(2);
Participating Frequently
February 4, 2025

OMG It worked! You are amazing! Thank you so much.