Skip to main content
Participant
January 14, 2018
Question

Dropdown choice translation into values

  • January 14, 2018
  • 3 replies
  • 910 views

Hello, I have created a character sheet for a game and I am stuck trying to translate drop down menu choices into numerical values to work with. The point is that a character is supposed to gain different bonuses according to the race chosen (as shown in the human/elf example below). Now I have the dropdown menu "Races" and I would like to have all the "racialmodXXX" added to the corresponding text fields (for example the "Agilitytotal" text field should be computed by adding the entered value in the "Agility" text field + "racialmodagi".)

This is what I have entered into the validation box of the "Races" dropdown menu:

var racetype = this.getField('Races');

var racialmodbody = '0';

var racialmodagi = '0';

var racialmodreac = '0';

var racialmodstr = '0';

var racialmodwill = '0';

var racialmodlog = '0';

var racialmodint = '0';

var racialmodcha = '0';

var racialmodedge = '0';

var racialmodmag = '0';

if (racetype.value == 'Human')

  {

racialmodbody.value='0';

racialmodagi.value='0';

racialmodreac.value='0';

racialmodstr.value='0';

racialmodwill.value='0';

racialmodlog.value='0';

racialmodint.value='0';

racialmodcha.value='0';

racialmodedge.value='1';

racialmodmag.value='0';

}

if (racetype.value == 'Elf')

  {

racialmodbody.value='0';

racialmodagi.value='1';

racialmodreac.value='0';

racialmodstr.value='0';

racialmodwill.value='0';

racialmodlog.value='0';

racialmodint.value='0';

racialmodcha.value='2';

racialmodedge.value='0';

racialmodmag.value='0';

}

The text field "Agilitytotal" is supposed to report "(Agility) + (racialmodagi)" by calculation but it doesn't. Once I remove (racialmodagi) from the calculation window, it works properly.

Sorry for the wall of text but maybe some of you have an idea how to solve this.

Thanks a lot in advance!

This topic has been closed for replies.

3 replies

Thom Parker
Community Expert
Community Expert
January 15, 2018

Read this article:

https://acrobatusers.com/tutorials/change_another_field

It'll show you how to best organize your data, and the correct way to set other values.

And since your interested in games, here is an example as PDF as a game platform, look at the Swat The Fly game on this page:

Free Sample PDF Files with scripts

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
January 15, 2018

@Thom Thanks a lot! Actually I was looking to find example PDFs for me to learn. I will definately check these out.
I was able to change data with simple methods but the problem I seem to have with the dropdownmenu is that I need each "choice" to influence multiple variables accross the PDF (instead of just one).

@try67 Thanks for your effort. Unfortunately I can't distribute the PDFs as they contain copyrighted material.

@gkaiseril I'm too inexperienced to actually have an opinion on that.

Inspiring
January 15, 2018

This looks like a situation to use the JavaScript prototype.

try67
Community Expert
Community Expert
January 14, 2018

Drop the quotes around all the numbers in your code.

Participant
January 14, 2018

Thanks. I have tried your suggestion but it didn't solve the problem.

try67
Community Expert
Community Expert
January 14, 2018

Post your full code, please. Also, why did you place it as a validation script, and not a calculation one?