These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Problems rounding down on a form.

LeleyX
Registered: Feb 8 2011
Posts: 6
Answered

I'm setting up a form for an RPG character sheet, but the basic problem is this, I have these stats, and I need to have a formula that will do the stat-10 then divide it by 2, and round it all down.
This is what I came up with:
 
var a = this.getField("STR");
event.value = Math.floor(("a"-10)/2)
 
But when I go to preview all I get is NaN.
 
Help please?

My Product Information:
Acrobat Pro 10.0, Windows
try67
Online
Expert
Registered: Oct 30 2008
Posts: 2399
Change the code to:
var a = this.getField("STR").value;
if (a!="") {event.value = Math.floor((a-10)/2)} else event.value = "";

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Accepted Answer
Your line of code;

var a = this.getField("STR");

Only obtains the value of the field named "STR".

Try the following code and think about what is being displayed.

console.show();
console.clear();
// get field object for STR
var a = this.getField("STR");
console.println('type of a: ' + typeof a);
console.println('value property of a: ' + a.value);
console.println('type of a.value: ' + typeof a.value);

// compute the vale of the value of a less 10 divided by 2
event.value = Math.floor((a.value - 10) / 2 )


George Kaiser

LeleyX
Registered: Feb 8 2011
Posts: 6
Great, it worked perfectly, thank you!