Copy link to clipboard
Copied
Hey, Hoping someone can help me. I am tring to create a field notation where it pulls the salary (from another field) and rounds it up to the nearest $100. Do I need to use java script? Please help!
Copy link to clipboard
Copied
This requires a script.
Copy link to clipboard
Copied
There are several ways to do this.
Here's one script that will work.
var nSalary = Number(this.getField("Salary").value);
event.value = Math.round(/100)*100;
You'll need to change the "Salary" field name to the name of this field on your form.
Also, the script assumes a valid number, or blank is entered into the "Salary" field. If this is not a valid assumption, then the script will need additional code to protect the calculation.
Copy link to clipboard
Copied
Thank you so much Thom. It comes back saying "SyntaxError: unterminated regular ex pression literal 1: at line 2
Im completely new at this so I would really appreciate any help. The salary field is called "Salary" and the field I am trying to pull that to and round up is called "TotalCoverage" if that helps?
Copy link to clipboard
Copied
Use:
var nSalary = Number(this.getField("Salary").value); event.value = Math.round(nSalary/100)*100;
Copy link to clipboard
Copied
Sorry about that. The script is missing a variable. Got lost in editing 😞 Bernd has shown the corrected code.
var nSalary = Number(this.getField("Salary").value);
event.value = Math.round(nSalary/100)*100;
Copy link to clipboard
Copied
This is great thank you.
One last question: If I wanted to take the Salary and round that up to the nearest thousand and then multiply it by 2.5 what would I do? I tried this on my own but its not rounding properly
Copy link to clipboard
Copied
Use this:
event.value = (Math.round(nSalary/1000)*1000) * 2.5;
Copy link to clipboard
Copied
thanks! this worked!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now