Copy link to clipboard
Copied
I am new to Javascript and trying to create PDF form which will calculate PV (present value) value for based on fields like Rate, Nper & PMT. Please help me regarding this. I think people with good experience about Javascript can solve this.
Copy link to clipboard
Copied
That's happening because you're trying to divide by zero.
Use this instead:
var R = Number(this.getField("Rate").valueAsString);
var N = Number(this.getField("NPER").valueAsString);
var P = Number(this.getField("PMT").valueAsString);
if (R!=0) {
event.value =P*(1-(Math.pow((1+(R/100)),-N)))/(R/100);
} else event.value = "";
Copy link to clipboard
Copied
This has been asked before. Have you used the search feature?
Do we need to supply the formula and code?
Copy link to clipboard
Copied
Hi, I used search but I could not find PV formula which I can use to get the result. Please supply the formula and code and kindly also help me how to put and where to put the code so it executes. I really don't have Javascript knowledge. Thank you
Copy link to clipboard
Copied
What I need is that I will fill Rate, Nper, and PMT in the fields and value will display in another field. Please help
Copy link to clipboard
Copied
You expect us to do your work for you? If you want help with it provide the formula and we could help you convert it to JS code.
Copy link to clipboard
Copied
This is the image which shows what I need. In yellow cell (excel), I wnt this in PDF form and I will enter the data and PDF form which will calculate the data in the other cells. In Column C what is the method required to get the data in column D. Pls help
Copy link to clipboard
Copied
This screenshot is useless. Provide the detailed formula, or at the very least describe the way it is done in Excel.
Copy link to clipboard
Copied
I am using this formula for pv
R = this.getField("Rate").value;
N = this.getField("NPER").value;
P = this.getField("PMT").value;
event.value =P*(1-(Math.pow((1+(R/100)),-N)))/(R/100);
Copy link to clipboard
Copied
It seems like you already have the code that does it...
Copy link to clipboard
Copied
The code is working but thing is that until I enter the value in the form , it keeps on showing me alert messages which says "the value entered doesnt match the format of the field. How to remove this alert message?
Copy link to clipboard
Copied
That's happening because you're trying to divide by zero.
Use this instead:
var R = Number(this.getField("Rate").valueAsString);
var N = Number(this.getField("NPER").valueAsString);
var P = Number(this.getField("PMT").valueAsString);
if (R!=0) {
event.value =P*(1-(Math.pow((1+(R/100)),-N)))/(R/100);
} else event.value = "";
Copy link to clipboard
Copied
Can I put If...else statement which you showed throughout the fields in the PDF forms?
Copy link to clipboard
Copied
Not sure what you mean...
Copy link to clipboard
Copied
I mean I have several fields in the PDF form which are same as I sent you in the Excel image. All the fields are showing the same alert message . Example I am sending you
This is for APV field code
if(this.getField("APV")!==0)
{
event.value = getField("NOI").value/ getField("CR").value*100;
}
else
{
event.value=0;
}
I have set the fields code in javascript like this in all the fields using If...else statement. Now I am getting such alert messages.
Copy link to clipboard
Copied
Your code is not correct. Go back to the sample I provided and study it carefully.
You need to check if the denominator in each calculation is zero.
Copy link to clipboard
Copied
Can you please make (correct) this code ?
if (this.getField("APV")!==0)
{
event.value = getField("NOI").value/ getField("CR").value*100;
}
else
{
event.value=0;
}
then I will follow and repeat the same throughout the form.
Copy link to clipboard
Copied
You must test the value of the field APV.
Copy link to clipboard
Copied
You must test the value of the field, but not APV, as it has nothing to do with this calculation... In this case, replace the first line with:
if (Number(this.getField("CR").valueAsString)!==0)
Copy link to clipboard
Copied
thank you it is working. but now there are other problems as the calculations is based on the field values which are scattered in the form so some of the calculation is not happening. I tried setting calculation order also but it also didnt work well.Do you suggest another method for this?
Copy link to clipboard
Copied
Setting the calculation order should solve the issue. If it didn't there's probably some kind of error. Did you check the JS-Console?
Copy link to clipboard
Copied
It didn't, can I share the file with you, please? I have minimum JS knowledge so having difficulty.
Copy link to clipboard
Copied
Yes, you can email it to me to try6767 at gmail.com, or upload it to a file-sharing website (Dropbox, Google Drive, Adobe Send & Track, etc.) and then post the link to it here.
Copy link to clipboard
Copied
Thank you, I have sent you two files. Please see if the problem can be solved.
Copy link to clipboard
Copied
I emailed you
Find more inspiration, events, and resources on the new Adobe Community
Explore Now