Simple Java: if dropdown option x is selected, return y immediately

Explorer ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

Looking for the best way to, essentially, replace a user's dropdown entry immediately to 10 if they select option: String, export value set to: 0. Dropdown field is fund1. There is a calculation script in a hidden field referencing fund1. 

 

I've tried adding a condition to that calculation such as 

if (fund1.value== 0) {fund1.value = 10} -> error: set not possible.

 

 

 

 

 

 

 

TOPICS
JavaScript , PDF forms

Views

55

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
community guidelines
Community Expert ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

You want to show 10 instead of "String" or you want export value to be 10?

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
community guidelines
Explorer ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

Thanks for your quick response. I'm lacking the correct terminology here.

In dropdown properties of fund1, the First item reads:

Item: String

Export Value: 0

The Second item in the list reads:

Item: String 2

Export Value: 10

 

I want to show the Second item if the First item is selected by the user. (Sometimes scripts involving dropdown refer to the export value, and sometimes to the 'item' or face value, as I believe it is called. This is not entirely clear to me.)

 

 

 

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
community guidelines
Community Expert ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

In that case, use the script provided by try67.

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
community guidelines
Community Expert ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

Odd request. Why add an option to the drop-down if the user can't select it?

But anyway, to do it move the code to the calculation event of the drop-down itself, and change it to this:

 

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

 

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
community guidelines
Explorer ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

Yes. omg. 

Field validation wouldn't work because the calculation performed the moment the user input was commited. 

Same with Format script. 

With your solution, I just have to prioritize this field in the calculation order

Thank you.

RE: "odd request": you're absolutely right. 🙂 The unselectable option was included to serve as a field label for the user. Many of the fields are not labeled externally, but contain a "label" within, in the form of an unselectable item. So far, it is a clean solution for the purpose.

 

How do I write a script with the same functionality as above, but to include in my main calculation event?

In otherwords, if my main calculation triggers whenever any field is changed, how can I include in that script a bit that triggers only if fund1 is changed? I hope that is clear.

 

 

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
community guidelines
Community Expert ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

You can check the value of event.source.name. It's the name of the field that triggered the calculation.

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
community guidelines
Community Expert ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

LATEST

Note that event.source itself can be null, though, so you might want to check for that first.

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