Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with formula in a form

Status
Not open for further replies.

EricaB

Technical User
Sep 26, 2007
6
US
Hello,

I'm working on a form in Acrobat 8. On page one the user enters all their contact info and their age. On page 5 I have a section that tells them what their heart rate should be at/around. I would like this to automatically fill when their enter in their age in the beginning. So I created a text field next to the heart rate copy and in the text properties under the Calculate tab I entered this javascript:
var n = "220";
var a = this.getField(age);
var p = ".5";
var s = "6";
function heartrate()
{
var hr = n - a * p / s;
document.write ("+hr+");
}
I'm not getting any errors, but also, nothing is calculating, my field is blank. Am I missing something?? The field that the user types in their age is called age.

The calulation my client uses to figure out the heart rate is as follows:
220 - age=Y then take 50,60,70,80, and 90 of Y, then divide each by 6

HELP!!!
Erica
 
I can see a few things:

1. ) this.getField(age) is not correct JavaScript (unless you create your own getField() function - which you didn't).
2. ) you need to get the age not when the page loads, but when the heartrate() function is called.
3. ) you are declaring your variables as Strings when they need to be just numbers.

Let's try this:
Code:
function heartrate() {
var n = 220;
var a = parseInt(document.getElementById('age').value,10);
var p = 0.5;
var s = 6;
var hr = n - a * p / s;
alert(hr);
return hr;
}
I'm thinking that you will need to put the returned value into the appropriate field on your page, but since I don't know much about PDF scripting and forms - you are on your own there.

Einstein47
“Evil abounds when good men do nothing.“ - Nelson R.
[[]Starbase47.com]
 
Thanks Einstein,

This was helpful, but when I put it in the Calculate tab for the heartrate field it still didn't work. This is my first time doing javascript in Acrobat. I thought I saw the Help files mention the "this.getField(name)" but I could have miss read it.

Hopefully someone else will have some advice.

Thanks,
Erica
 
I figured it out...I was doing it the hard way and by using the Simplified field notation I was able to make it work. I swear I tried that before and it didn't work.
(220 - age)*0.5/6

Thank you,
Erica
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top