Dropdown choice translation into values

Community Beginner ,
Jan 14, 2018

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript

Views

188

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Dropdown choice translation into values

Community Beginner ,
Jan 14, 2018

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript

Views

189

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 14, 2018 0
Most Valuable Participant ,
Jan 14, 2018

Copy link to clipboard

Copied

Drop the quotes around all the numbers in your code.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2018 1
Community Beginner ,
Jan 14, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2018 0
Most Valuable Participant ,
Jan 14, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2018 1
Most Valuable Participant ,
Jan 14, 2018

Copy link to clipboard

Copied

Ah, I think I see now what you tried to do... It should work, but you should replace all the instances of:

racetype.value

With:

event.value

Also, make sure to tick the option to commit the selected value immediately, under the drop-down's Properties, Options tab.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2018 1
Community Beginner ,
Jan 14, 2018

Copy link to clipboard

Copied

Thanks for your reply. I have tried all your suggestions without success.

About your questions:
Why the validation window?
Since the dropdown menu does not really calculate and only serves as a setup for calculation on other fields I thought the calculation should be put into those other fields and I didn't see any other option to put the code in except for validation.

What I was trying to do?
1. Create text fields for 8 attributes where users enter numbers.
2. Create drop down menu and enter races.
3. Translate each race into numerical values and write these values into hidden variables.
4. Behind the 8 attribute text fields there are 8 attributetotal text fields. These 8 fields should show the combined result of the data entered in 1. + the data from the hidden variable (according to chosen race) for each field

Calculation works fine between all text fields.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2018 0
Most Valuable Participant ,
Jan 14, 2018

Copy link to clipboard

Copied

Can you post your current code, or (better yet) share the file (via Dropbox, Google Drive, Adobe Cloud, etc.)?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2018 1
Adobe Community Professional ,
Jan 15, 2018

Copy link to clipboard

Copied

This looks like a situation to use the JavaScript prototype.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 15, 2018 1
Adobe Community Professional ,
Jan 15, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 15, 2018 2
Community Beginner ,
Jan 15, 2018

Copy link to clipboard

Copied

@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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 15, 2018 0