Skip to main content
Participant
July 17, 2020
Answered

Monthly/Annually Fields update based on eachother's value

  • July 17, 2020
  • 1 reply
  • 800 views

Hello! 

 

I am trying to make it so Monthly/Annually both update based on the value that is entered or updated.

Is it possible to get each of these 2 fields to update once either is filled in or when the value of either is changed? 

It seems i can get one field to calculate based on the other but not vice versa .

 

event.value = Number(this.getField("txt_Annually").value) / 12;      in Monthly field

event.value = Number(this.getField("txt_Monthly").value) * 12;      in Annually field

I currently have these 2 calculations in each respective field. At the moment it doesnt allow you to alter the value inside the Monthly field.

 

Any advice would be greatly appreciated!

 

This topic has been closed for replies.
Correct answer ls_rbls

You can try it like this:

 

//Place this code as custom calculation script of Monthly field

if (event.source && event.source.name =="txt_Annually") {event.value = Number(this.getField("txt_Annually").value/12);}
else event.value = event.target.value;


//and place this code as custom calc script of the Annually field

if (event.source && event.source.name =="txt_Monthly") {event.value = Number(this.getField("txt_Monthly").value*12);}
else event.value = event.target.value;

 

Note: Credit to Try67 who coached me on how to apply (event.source && event.source.name)  a while ago.

 

This will allow both fields to calculate based on each other's values and remain editable.

1 reply

ls_rbls
Community Expert
ls_rblsCommunity ExpertCorrect answer
Community Expert
July 18, 2020

You can try it like this:

 

//Place this code as custom calculation script of Monthly field

if (event.source && event.source.name =="txt_Annually") {event.value = Number(this.getField("txt_Annually").value/12);}
else event.value = event.target.value;


//and place this code as custom calc script of the Annually field

if (event.source && event.source.name =="txt_Monthly") {event.value = Number(this.getField("txt_Monthly").value*12);}
else event.value = event.target.value;

 

Note: Credit to Try67 who coached me on how to apply (event.source && event.source.name)  a while ago.

 

This will allow both fields to calculate based on each other's values and remain editable.

Participant
July 18, 2020

Thank you! Thought it might be something like this.

ls_rbls
Community Expert
Community Expert
July 18, 2020

You're welcome.