
1. Re: Help! help! How come Math pow( ) cannot work on this????
gkaiseril Oct 15, 2016 7:58 PM (in response to tanw35138092)Math.pow cannot be used in the simplified field notation. Yo need to use the custom JavaScript calculation option.
You cannot have blanks, spaces, or special characters in field names using simplified field notatio unless you use the JavaScript Escape character.
Are you getting any error messages in the JavaScript console?

2. Re: Help! help! How come Math pow( ) cannot work on this????
tanw35138092 Oct 15, 2016 8:11 PM (in response to tanw35138092)Thanks for reply.
Retrying on the custom JavaScipt calculation option.
12*m*(Math.pow(11.02,S))/11.02
m=monthly amount
S=no. of year
but still not working... sorry no experience in using javascript... please..please help.
still not working for both option.
No error messages in the JavaScript console for both simplified and custom option.

3. Re: Help! help! How come Math pow( ) cannot work on this????
gkaiseril Oct 15, 2016 8:29 PM (in response to tanw35138092)Use Ctrl +J keys to open the JavaScript console. Bothscripts are generating errors.
In JavaScript you need to access the field object using "getField" and then the value property of the field object.

4. Re: Help! help! How come Math pow( ) cannot work on this????
tanw35138092 Oct 15, 2016 8:51 PM (in response to tanw35138092)Thanks!
This is what i have from the JavaScript Debugger:
ReferenceError: m is not defined
1:Field:Calculate
ReferenceError: m is not defined
1:Field:Calculate
for m is not defined? what does that mean already created the field??

5. Re: Help! help! How come Math pow( ) cannot work on this????
gkaiseril Oct 15, 2016 9:23 PM (in response to tanw35138092)You did not access the field properly.

6. Re: Help! help! How come Math pow( ) cannot work on this????
tanw35138092 Oct 15, 2016 10:22 PM (in response to tanw35138092)Hi, Sorry, do you have any other way to solve this
maybe my script is not the correct way to work.
because if I use S*m it will turn out correctly (S=No of year) x(M=Monthly amount)
but adding the Math.pow it will...encounter problem.
Basically, it is supose to work on the row 1 (see attached hightlighted)
Each year (12 months) x No of years (eg 2 years) x Monthly amount (1,000) x (1 the interest rate (1.02)Math pow of (no of year(2 year) divided by 110.02) total amount of the first row will be S$24240.
Awaiting for your help...please.
Regards
Thanks

7. Re: Help! help! How come Math pow( ) cannot work on this????
tanw35138092 Oct 15, 2016 10:25 PM (in response to tanw35138092)Sorry, should be
Each year (12 months) x No of years (eg 2 years) x Monthly amount (1,000) x (1 the interest rate (1.02)Math pow of (no of year(2 year) divided by 11.02) total amount of the first row will be S$24240.

8. Re: Help! help! How come Math pow( ) cannot work on this????
Test Screen Name Oct 16, 2016 2:08 AM (in response to tanw35138092)1. Converting from simplified field notation to full JavaScript is more than just choosing the option. Your JavaScript must do some of the things that were automatic in the simplified form. In particular, you must CONNECT every field you work with to a variable (except in some kinds of event, where you must NOT do this and have a special variable instead). Commonly, one uses getField to connect to variables. You must use "m" expecting it to contain the value of the field "m"  no, you can't, and that's why it is undefined.
2. Obviously something is very wrong with the formula as you've expressed it. 11.02 is always 0.02.
So for one year the result is pow(0.02,1) = 0.02. For two years, pow(0.02,2) = 0.02 * 0.02 = +0.004. For three years, pow(0.02,3) = 0.02 * 0.02 * 0.02 = 0.0008. So your results are alternatively negative and positive, and rapidly get very small indeed. This is not a JavaScript issue, but a mathematical misunderstanding of something, to solve before coding.

9. Re: Help! help! How come Math pow( ) cannot work on this????
tanw35138092 Oct 16, 2016 3:58 AM (in response to tanw35138092)Hi, Thank for replying
I think you misunderstand the math pow part.
It should be 1.02 pow of (2 years,3 years ...etc)(is just the 1.02 pow of...)
result for one year 11.02=0.02, 2 years=1 (1.02 * 1.02)= 0.0404, 3 years=1(1.02 * 1.02 * 1.02)=0.06121
Or try this ways
Monthly amount (1,000) x ( the interest rate (1.02)Math pow of (no of year(2 year)1, divided by 0.02) x Each year (12 months) x No of years (eg 2 years) = total amount of the first row will be S$24240.
thanks

10. Re: Help! help! How come Math pow( ) cannot work on this????
Test Screen Name Oct 16, 2016 4:48 AM (in response to tanw35138092)I think I understood what the Math.pow part actually DID. I didn't understand what you wanted to do. You wrote
Math.pow(11.02,No. of years)
which gives the result I said. Because the first thing that must happen is 11.02 so what you write is EXACTLY the same as
Math.pow(0.02,No. of years)
You probably want something more like
1Math.pow(1.02,No. of years)

11. Re: Help! help! How come Math pow( ) cannot work on this????
tanw35138092 Oct 16, 2016 5:08 AM (in response to tanw35138092)Hi, Sorry for not interpret properly.
Yap, this is what i mean
1Math.pow(1.02,No. of years)
So one year 11.02=0.02, 2 years=1 (1.02 * 1.02)= 0.0404, 3 years=1(1.02 * 1.02 * 1.02)=0.06121
Will it it work for coding? Really appreciate for your patients.
Thank you.

12. Re: Help! help! How come Math pow( ) cannot work on this????
Test Screen Name Oct 16, 2016 6:14 AM (in response to tanw35138092)Try it, check the result, if it doesn't work please copy and paste the new code and the JavaScript console messages.

13. Re: Help! help! How come Math pow( ) cannot work on this????
tanw35138092 Oct 16, 2016 7:07 AM (in response to tanw35138092)Hi, is still not working...
Script:
12*mth*(1Math.pow(1.02,NY))/11.02
Console messages
ReferenceError: mth is not defined
1:AcroForm:total:Calculate
pdf file: http://adobe.ly/2dkAu3k
Hope to hear from you soon.

14. Re: Help! help! How come Math pow( ) cannot work on this????
try67 Oct 16, 2016 8:40 AM (in response to tanw35138092)In order to access a field's value in JavaScript you can't just type the field's name. You have to use the appropriate methods and properties. So, for example, to get the value of a field called "mth" you need to use something like this:
var mth = this.getField("mth").value;
Then you can use the "mth" variable you've defined in the rest of your code.

15. Re: Help! help! How come Math pow( ) cannot work on this????
gkaiseril Oct 16, 2016 9:02 AM (in response to tanw35138092)It appears you are still trying to use the simplified field syntax for JavaScript. You cannot do this.
JavaScript is an object orientated language. That is, one must first link to an object like a field and then using that link access a property like the field's value or a method of the object.
One accesses a field object and then the properties or methods of that object.
You might want to look over the Acrobat JavaScript API Reference and the MDN JavaScript Reference as well as the various tutorials and videos posted by Adobe.
Your script for custom JavaScript calculation could read:
event.value = 12 * this.getField("mth").value * ( 1 Math.pow(1.02, this.getField(("NY").value)) / 1  1.02

16. Re: Help! help! How come Math pow( ) cannot work on this????
tanw35138092 Oct 16, 2016 11:22 AM (in response to tanw35138092)Thanks for reply,
By using your
event.value = 12 * this.getField("mth").value * ( 1 Math.pow(1.02, this.getField(("NY").value)) / 1  1.02
It appear message: SyntextError missing) in parenthetical line1: at line2
So i key in
event.value = 12 * this.getField("mth").value * ( 1 Math.pow(1.02, this.getField(("NY").value)) / 1  1.02);
it work but the total answer is not right it appear 1224
it there something right, please advise.

17. Re: Help! help! How come Math pow( ) cannot work on this????
Test Screen Name Oct 16, 2016 12:19 PM (in response to tanw35138092)Why do you have (( instead of ( for the getField of field NY?

18. Re: Help! help! How come Math pow( ) cannot work on this????
tanw35138092 Oct 16, 2016 2:20 PM (in response to tanw35138092)Hi,
tried a few ways but still cannot get the correct answer that i have, just wondering is there anything wrong with Math.pow part..
Please advise.

19. Re: Help! help! How come Math pow( ) cannot work on this????
Test Screen Name Oct 16, 2016 2:24 PM (in response to tanw35138092)Looks wrong to me. Especially the two brackets. What are you trying to do there, and why is it different from the other getField? Since we didn't tell you to do that, presumably there was a reason that you did. Maybe it's a good reason. We can't know what is wrong without understanding why you did what you did.

20. Re: Help! help! How come Math pow( ) cannot work on this????
Karl Heinz Kremer Oct 16, 2016 3:05 PM (in response to tanw35138092)There is a mistake in gkaiseril's code that you copied. In general, it's a bad idea to try to copy&paste code snippets you find online without knowing what you are doing. You've admitted that you don't know anything about JavaScript, and you will have to work on that. Otherwise, it's impossible to create a Javascript solution to a problem. We all make mistakes, and sometimes these mistakes make it into sample code. You need to be able to look at a line of code and realize that it's wrong by knowing basic Javascript syntax. There is no way around that. Do yourself a favor and get a good introduction to JavaScript and read the chapters about the basic syntax. You will feel a lot more comfortable afterwards  and more competent  when it comes to figuring out what's wrong with a script.
For beginners, it's usually very hard to wrap your head around an expression that has a lot of layers (e.g. function call inside a parameter to another function call). It's easier to define your variables upfront, and then use them when you need them. Let me give you an example in pseudo code:
You are using something like this:
someVariable = someFunction(someConstant, someOtherFunction("a string").method);
Your code actually has a lot more parts to the expression. What you can do do make this a bit easier to swallow is break out the call to someOtherFunction() like this:
var functionArgument = someOtherFunction("a string").method; someVariable = someFunction(someConstant, functionArgument);
As you can see, your line #2 is now much shorter, and easier to understand.
You can define your two variables that you need for the two form field values upfront, and then use them when you need them by just referencing the variables:
var mth = this.getField("mth").value; var NY = this.getField("NY").value;
Once you get the basic formula working, you need to work on checking your input data and only calculate an output value is your input data is actually valid, but that's stuff for another day.