Skip to main content
Inspiring
November 6, 2022
Answered

Need Help creating a form calculation involving checkboxes

  • November 6, 2022
  • 3 replies
  • 1983 views

Ok, so here's what I have.. and I'm clueless as to what is going on because I can't figure it out. Using other examples on the forums I have the following code: 

var oFldSel = this.getField("Weapon1.Proficiency.Bonus1");

if(oFldSel)
{
switch(oFldSel.value)
{
case "Trained":
event.value = 2;
break;
case "Expert":
event.value = 4;
break;
case "Master":
event.value = 6;
break;
case "Legend":
event.value = 8;
break;
default:
event.value = 0;
break;
}
}

 

Ok, so when radio button 1 (trained) is selected it changes the value of the field to 2, likewise the others change appropriately. However, when I get to the final calculation which calculates the entire weapon bonus using strength modifier (almost never changes), Proficiency Bonus (changes per level of character and per level of proficiency) and an item modifier (which could change at any time) it's showing the OLD value of the proficiency bonus. Example: Proficiency Bonus orignally +2 but proficiency level increases to +4, total stays with the +2 value unless changed again then it takes the +4 value. 

 

I'm including the copy of the character sheet I'm trying to set up.. Can anyone help me please? It's giving me a headache and frustrating as f***!! 

This topic has been closed for replies.
Correct answer Joshua Laloge

Sure it is. In your version it's under Tools - Forms - Edit, then Other Tasks - Set Fields Calculation Order.


Ok, found it. And ironically, I also figured the problem out and got it to work. Instead of doing the "Is value of sum+" option, I set it for a simplified and entered the fields manually using the following formula: 

(STRMod+PROF2)+(ITEM2+Level)

This solves the problem perfectly. So I'm gonna post this message as the correct answer and upload with it the new copy of the character sheet I'm working on so that anyone else who needs it can see what I did and maybe it can help them. I would also like to say I would not have figured this out if it had not been for everyone here helping so you guys still get the credit. Thank you very much for your assistance and maybe you can help on the next problem I'm having, getting the form to round down.

 

Formula is as follows: 

 

STRMod = (Strength-10)/2 

thing is, it needs to round it down. So if formula is (15-10)/2= 2.5 I need it to print 2 and not 3

3 replies

try67
Community Expert
Community Expert
November 6, 2022

There are multiple errors in your calculations, starting with a field that has the Sum option selected but no actual fields, then incorrect field names selected (which triggers an error), to the wrong fields being used, etc., but the issue you're describing is typically caused by an incorrect calculation order.

Bernd Alheit
Community Expert
Community Expert
November 6, 2022

Change the field calculation order.

Inspiring
November 7, 2022

forgive me please, I don't know how to do that. Are you talking about the final calculation? I don't have any way to select the order it calculates in, it's all alphabetical and I don't know how to change that.

Nesa Nurani
Community Expert
Community Expert
November 7, 2022

To change field calculation order:

Select 'Prepare form' tool, click on 'More' then select 'Set field calculation order'. Fields that calculate first should be on top.

 

EDIT:

Also, you should fix what Try67 mentioned.
1. In field "PROF2" script change field name to "Weapon_2_Proficiency.1".
2. In field "Attack.Bonus.2" you have selected field "ITEM_2" which you after that
changed to "ITEM2" so now you need to reselect(pick) that field again for calculation to work.
3. In field "PROF" script you didn't set 'default' it's not that important, just a tip.
4. In field "Weapon.1.Attack.Bonus.1" you selected 'Value is the' but not picked any fields.
5. Field calculation order should be:
PROF
PROF2
Attack.Bonus.2
6. For both weapon1 and weapon2 section you have a field with same name "STRMod" you may want to change that to "STRMod1" and "STRMod2" unless it's on purpose.

Just a tip: don't change fields names after you select them for calculation, or your scripts won't work,
take a look at your design and decide what would be the best field naming for each section before you start work.

Inspiring
November 6, 2022

I found a work-around though I would still like to use the radio buttons, but for now the work around was found from this: https://community.adobe.com/t5/acrobat-discussions/checkboxes-values-calculations/td-p/11175039