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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adobe 9 text fields and calculations 2

Status
Not open for further replies.

CecilXavier

Technical User
Oct 2, 2007
104
US
I am not well versed in Javascript. Please be patient.
I am trying to have on field in adobe acrobat 9 populate from another fields input. Basically if one field has an 18 in it I would like the other field to automatically populate with a +3.
Can anyone explain to me how to do this using the javascript custom calculation box? Or any other way would work. As long as I can do it.

Also:
I am trying to create a calculation form in Adobe acrobat 9. I have an item named CHALEV. I would like another textbox to calculate 1/2 (Round down) the number placed into CHALEV. CHALEV is calcualted by taking the sum of 6 other fields. I am pretty sure I need to use the command math.floor, but I do not know much about javascript and I do no know how to tell it to use the item calculated for the text box CHALEV. Any help would be great.

I have 2 separate questions. I am trying to create a working character sheet for SWRPG SE.
 
Hi CecilXavier

If field1 = 18 then you want field2 to = 18 +3 or 21?
If so that would just be field2 = field1 + 3

Question 2
For CHALEV you make a field CHALEV2 or whatever and make the calculation CHALEV2 = CHALEV * .50

Can you post what you have on the internet so I can see it?

IMacQuarker
 
For Question 2:

It's in a pdf that I am using. Let say I have 2 text boxes on this pdf. One called CHALEV the other called CHALEV2. Bare in mind this is just the name of the text field that I named it when adobe 9 asked what to name it.
I want, whenever I enter a value in CHALEV for it to calculate an output to CHALEV2 of .5 rounded down.
I believe I am going to use the math.floor() command. Here is where I am having issues. I either have to have a javascript calculation that exports from CHALEV to CHALEV2 or I need CHALEV2 to Read from CHALEV and calculate .5 rounded down.
I am used to having a field like CHALEV having a format of CHALEV.Text or CHALEV.input when I work in VB. I am not used to how it works when editing a Adobe PDF

Question 1:

I basically want to make an if then statement. If Str = 18 then Str Modifier = +3. If Str = 16 then Str Modifier = +2, So forth and so on. I don't know how the naming convension works when using javascript in an adobe pdf. This is where I am lost.

Hope that clarifies what I am asking.
 
Hi CecilXavier

I am still not completely sure exactly what you want.
However if you want to do a number calculation you first have to format the text boxes to contain a number then you go to calculations and do the calculation.

This is what the following script does.
You should be able to modify it to do what you want.

If Str = 1, 2 or 3 then Str Modified = 3
If Str = 3, 4 or 5 then Str Modified = 4
If Str = 5, 6 or 7 then Str Modified = 5

Here is the script which you can change to what you want;
_____________________
var nstr = this.getField("str").value;
if( nstr < 1 )
event.value = nstr = "";
else if( nstr <= 3 )
event.value = nstr = 3;
else if( nstr <= 6 )
event.value = nstr = 4;
else if( nstr <= 9 )
event.value = nstr = 5;
else
event.value = 0;
________________________________
Go here to see the PDF. You can download it and open it in Acrobat to see how it works.

Hope this helps
IMacQuarker
 
Smashing! You answered my second question perfectly. So the "this.getField("").value" command is how to get info from another txt box as a value and work with it correct?
 
ok. I think I messed up somewhere. Here is the code I am using.

var nstr = this.getField("Str").value;
if( nstr < 1 )
event.value = nstr = "";
else if( nstr = 1 )
event.value = nstr = -5;
else if( nstr = 2 )
event.value = nstr = -4;
else if( nstr = 3 )
event.value = nstr = -4;
else if( nstr = 4 )
event.value = nstr = -3;
else if( nstr = 5 )
event.value = nstr = -3;
else if( nstr = 6 )
event.value = nstr = -2;
else if( nstr = 7 )
event.value = nstr = -2;
else if( nstr = 8 )
event.value = nstr = -1;
else if( nstr = 9 )
event.value = nstr = -1;
else if( nstr = 10 )
event.value = nstr = 0;
else if( nstr = 11 )
event.value = nstr = 0;
else if( nstr = 12 )
event.value = nstr = 1;
else if( nstr = 13 )
event.value = nstr = 1;
else if( nstr = 14 )
event.value = nstr = 2;
else if( nstr = 15 )
event.value = nstr = 2;
else if( nstr = 16 )
event.value = nstr = 3;
else if( nstr = 17 )
event.value = nstr = 3;
else if( nstr = 18 )
event.value = nstr = 4;
else
event.value = 0;

It keeps coming back with a value of -5 for Str Modifier. What did I do wrong?
 
Hi CecilXavie

It looks like you have to have the less than/equal to symbols <= to make it work.
Also that script is case sensitive so you can't use Str for str.
I reposted the PDF and I think it works now.
You will have to change the result to whatever you want.

var nstr = this.getField("str").value;
if( nstr < 1 )
event.value = nstr = "";
else if( nstr <= 1 )
event.value = nstr = -1;
else if( nstr <= 2 )
event.value = nstr = -2;
else if( nstr <= 4 )
event.value = nstr = -4;
else if( nstr <= 5 )
event.value = nstr = -5;
else if( nstr <= 6 )
event.value = nstr = -6;
else if( nstr <= 7 )
event.value = nstr = -7;
else if( nstr <= 8 )
event.value = nstr = -8;
else if( nstr <= 9 )
event.value = nstr = -9;
else if( nstr <= 10 )
event.value = nstr = -10;
else if( nstr <= 10 )
event.value = nstr = -10;
else if( nstr <= 11 )
event.value = nstr = -11;
else if( nstr <= 12 )
event.value = nstr = -12;
else if( nstr <= 13 )
event.value = nstr = -13;
else if( nstr <= 14 )
event.value = nstr = -14;
else if( nstr <= 15 )
event.value = nstr = -15;
else if( nstr <= 16 )
event.value = nstr = -16;
else if( nstr <= 17 )
event.value = nstr = -17;
else if( nstr <= 18 )
event.value = nstr = -18;
else
event.value = 0;

Go here


IMacQuarker
 
OK. Here is what I am trying to do with the CHALEV.

var level = CHALEV.value
event.field = Math.floor(level * .5)

I know I have this all wrong. I'm trying to take the Value of CHALEV and divide it in half. Rounding down.

Everything else works great now. Thank you.
 
Hi CecilXavier

I think I found a way to make the round down to work.
Try this
The Simplified field notation for Chalev2 = Chalev * .50
Then to round it down you go to Validate and paste this
event.value = Math.floor(event.value);
That seems to work here.
Try it

IMacQuarker
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top