Skip to main content
Participating Frequently
September 16, 2024
Answered

Javascript not running, does nothing

  • September 16, 2024
  • 3 replies
  • 817 views

Hi all, 

I need some help please, I'm doing a form were if you buy something over a certain amount it triggers a 24 month payment plan option and if you go over the next amount it triggers a 36 month plan as well. I've written some code using the IF command for the first time, it says there are no errors but when I add an amount a hit the button to run the calcucations it does nothing.

I've attached a screengrab of the form, how the boxes are formatted and the code is worded (below)



var total = this.getField (‘TotalValue’);

var IFCdeposit = this.getField (‘_IFCdepositsum’);

var IFCsum = this.getField (‘_IFCtermsum’);

var IFC24 = this.getField (‘_24IFCmonthly’);

var IFC36 = this.getField (‘_36IFCmonthly’);

 

if (total.value >= 12000.00) IFCdeposit.value = total.value * 0.50;

var IFCdepositCalc = total.value * 0.50;

IFCdeposit.value = IFCdepositCalc;

IFCsum.value = IFCdepositCalc;

 

if (IFCsum.value >= 6000.00)

var IFC24Calc = IFCsum.value / 24;

IFC24.value = IFC24Calc;

 

if (IFCsum.value >= 7500.00)

var IFC36Calc = IFCsum.value / 36;

IFC36.value = IFC36Calc;

Any help would be greatfully recieved, as I'm no coder......

Thanks Simon

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

There are few errors in your script, you have wrong quotes use these "TotalValue" or these 'TotalValue'.
You need to put if statements inside curly brackets like this:
if (total.value >= 12000.00) {
var IFCdepositCalc = total.value * 0.50;
IFCdeposit.value = IFCdepositCalc;
IFCsum.value = IFCdepositCalc;
}

3 replies

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
September 16, 2024

There are few errors in your script, you have wrong quotes use these "TotalValue" or these 'TotalValue'.
You need to put if statements inside curly brackets like this:
if (total.value >= 12000.00) {
var IFCdepositCalc = total.value * 0.50;
IFCdeposit.value = IFCdepositCalc;
IFCsum.value = IFCdepositCalc;
}

SiCritAuthor
Participating Frequently
September 16, 2024

thatnks was the ’ to ' that stopped it working cheers

 

Bernd Alheit
Community Expert
Community Expert
September 16, 2024

Check the Javascript console for errors (ctrl-j)

SiCritAuthor
Participating Frequently
September 16, 2024

sorry all noticed i put the wrong code up, it should be this

var total = this.getField (‘TotalValue’);

var IFCdeposit = this.getField (‘_IFCdepositsum’);

var IFCsum = this.getField (‘_IFCtermsum’);

var IFC24 = this.getField (‘_24IFCmonthly’);

var IFC36 = this.getField (‘_36IFCmonthly’);

 

if (total.value >= 12000.00)

var IFCdepositCalc = total.value * 0.50;

IFCdeposit.value = IFCdepositCalc;

IFCsum.value = IFCdepositCalc;

 

if (IFCsum.value >= 6000.00)

var IFC24Calc = IFCsum.value / 24;

IFC24.value = IFC24Calc;

 

if (IFCsum.value >= 7500.00)

var IFC36Calc = IFCsum.value / 36;

IFC36.value = IFC36Calc;