Skip to main content
Known Participant
September 15, 2021
Question

Need Help with calculation.

  • September 15, 2021
  • 1 reply
  • 716 views

Hi,

I need help with calculation. 
Text1 have value 5/100

Text 2 have value 100

 

Text 3 is product of Text1 and Text2. 

when I use simple product, it comes 510 as result. 
when I use below script, it comes NAN. 

 

var a = Number(this.getField("Text1").valueAsString);
var b = this.getField("Text2").value;

event.value = a*b;

 

I want to achieve 5 as result. I hope someone will help me. PDF is attached for reference. 

Thanks!

This topic has been closed for replies.

1 reply

Inspiring
September 16, 2021

You can't calculate like that.

Also you set text2 to be same as text1 so text2 is not 100 it's also 5/100.

Can you describe what you try to achive?

Why do you enter value as 5/100, why not use 5 and divide by 100 in script or just use result value of 0.05 since you already know what it is?

BhuweshAuthor
Known Participant
September 16, 2021

I can't use 5 and divide by 100. It can be any number it can 3/100 or just 3. So I want field 1 will work like below condition. 

 

If I write 5/100 in that field it multiply/divide other field with 0.05. 

If I write 3/100 in that field it multiply/divide other field with 0.03.

If I write 5 in that field it multiply/divide other field with 5.

 

Thom Parker
Community Expert
Community Expert
September 16, 2021

5/100 is a actually the JavaScript code for 5 divided by 100. So one way to achieve the result you want is to execute the entered text as if it was JavaScript. 

 

event.value = exec(this.getField("Text1").value) * this.getField("Text2").value;

 

of course. If the value of "Text1" is not executable JavaScript code there will be an error. So you'll either have to guarentee that condition, or add some error handling to the calculation script. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often