• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Trying to get a dropdown list to export the value of a different field

Community Beginner ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

 

Hello,

 

I am trying to automate an RPG character sheet.  I also have no programming background, so this is all scary to me!

 

So, I have fields called "STR", "RFL", "INT", "WIS", and "CHA".  These fields would all have a number put into them.

 

Then I have a Dropdown list called "Attribute" and the options are "STR", "RFL", etc.  I want the choice made in the Dropdown list to fill a field called "Value" with the value of the chosen field.  The "Value" field currently calculates with:


event.value=this.getField("Attribute").value;

It displays whatever I'm exporting from the dropdown list, but I can't get the export to be the value of the chosen field.

 

For example, let's say the field value for field "RFL" is 3.  When "RFL" is chosen in the dropdown list, I want the "Value" field to say 3.

 

Thanks

TOPICS
Edit and convert PDFs , How to , JavaScript

Views

636

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
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 26, 2022 Jul 26, 2022

Use this as 'Custom calculation script' of "SkillBonus_1" field:

var attr = this.getField("SkillAtt_1").valueAsString;
var attrField = this.getField(attr);
if (attrField==null) var skill = 0;
else skill = attrField.valueAsString;
if(skill == 0)event.value = "";
else
event.value = Number(this.getField("SkillRating_1").value)+Number(skill);

In dropdown fields properties ⇾ options tab ⇾ check 'Commit selected value immediately'.

Here is your file with script added and dropdown options ticked for fi

...

Votes

Translate

Translate
Community Expert ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Use this:

var attr = this.getField("Attribute").valueAsString;
var attrField = this.getField(attr);
if (attrField==null) event.value = "";
else event.value=attrField.valueAsString;

Votes

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
community guidelines
Community Beginner ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

Here's an example of my ignorance - where do I use this?  Maybe I need to give more detail.  The form will have the above Attributes, and then there will be a Skills section.  The Skills section looks like this:

 

Skill Name | Rating | Attribute | Bonus

 

The Skill Name is just a text field.  The "Rating" will be a number.  The Attribute will be the dropdown menu where the user chooses the applicable attribute (STR, RFL, etc.) The "Bonus" will be the sum of "Rating" and the corresponding Attribute chosen in the dropdown menu.  For  example:

 

Let's say STR = 3

Skill Name | Rating | Attribute | Bonus

Athletics     |     2     |     STR    |     5

 

So, I need to know 2 things:

  1.  What do I put as the Export Value in the dropdown menu so that when STR is chosen, it exports the value of the "STR" field (in this case 3)?
  2. What do I put in the "Bonus" field to make it add "Rating" and "Attribute" together?  I'm hoping to just calculate the sum of the two fields, but I'm happy to do whatever it takes.

 

Thanks again for helping!

 

Votes

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
community guidelines
Community Expert ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

Use script as 'Custom calculation script' of "Value" field. You don't need to add anything as export value.

You can use 'Simplified field notation (SFN)' to calculate "Bonus", just write field names in SFN like this:

Rating+Value

If you have delay in calculations check 'Field calcuation order' under ⇾ Prepare form tool ⇾ 'More' ⇾ Set field calculation order.

If you don't want to show 0 in field then as 'Validate' script of "Bonus" field use this:

if(event.value == 0)event.value = "";

Votes

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
community guidelines
Community Beginner ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

Ok, that sort of worked. 🙂

If I set the attribute first, then add a Rating, it would do the math, but the Attribute disappeared from the dropdown.

I've started my edits of this sheet from scratch, so all I've done is rename the fields in the first Skill (SkillName_1, SkillRating_1, SkillAtt_1, SkillBonus_1) and entered the Name and Ratings.  I hate to ask, but could you just make the fields work for that line and then I can do it to the rest of the lines?

Votes

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
community guidelines
Community Expert ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

Use this as 'Custom calculation script' of "SkillBonus_1" field:

var attr = this.getField("SkillAtt_1").valueAsString;
var attrField = this.getField(attr);
if (attrField==null) var skill = 0;
else skill = attrField.valueAsString;
if(skill == 0)event.value = "";
else
event.value = Number(this.getField("SkillRating_1").value)+Number(skill);

In dropdown fields properties ⇾ options tab ⇾ check 'Commit selected value immediately'.

Here is your file with script added and dropdown options ticked for first field:

https://drive.google.com/uc?export=download&id=1lD3XfVm19quCxYoXh4H7cocsTQAi9j7O 

Votes

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
community guidelines
Community Beginner ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

LATEST

Thank you so much!  Now I'll just copy and paste my way to a complete sheet, but soon I'll have to stare at it long enough for it to start making sense!

Votes

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
community guidelines