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

Radio button and field value determine new field value

Explorer ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

I'm developing a form that has a grading section where someone selects a dropdown grade of N/A or 1 to 5 per item. If the option N/A is selected then the export value would then equal "-". These selected values are then populated in a table in column1. In column2 the values are determined by a set of 3 radio buttons.

Sometimes an item is not applicable so it needs to be null and therefore wouldn't need a value in column2.

 

This is what I need to determine:

If

Item1 is >=  1 AND Radio1 is "YES"

then

Column2 value =="4"

or

If

Item1 is >= 1 AND Radio2 is YES

then

Column2 value =="3"

or

Item1 is >= 1 AND Radio3 is YES then

Column2 value =="5"

else

Column2 value ==null

 

I've been trying to hunt down the javascript reference to write all this but I've been hitting a lot of roadblocks. Can anyone help me out? Once I have a decent amount of script to go off of I can usually make the necessary adjustments to fit my needs. Any help would be greatly appreciated!

TOPICS
JavaScript , PDF forms

Views

2.2K

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 , May 05, 2021 May 05, 2021

You've found a clever solution. 

Here is the additon for Item1, assuming that is the actual field name.

 

if(this.getField("Item1").value != "-")
   event.value = oVals[getField("RadioSet").valueAsString];
else
   event.value = ""; 

 

Votes

Translate

Translate
Explorer ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

I've applied this custom calculation script to the field in column2. It works really well but not exactly what I need.

ar oVals = {

"Off" : "",

"Radio1" : 4,

"Radio2" : 5,

"Radio3" : 3,

};

event.value = oVals[getField("RadioSet").valueAsString];

 

How do I get the calculation to also factor if item1 is equal to or greater than 1 then run the script or else the column2 field stays blank?

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
Enthusiast ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

What are you try to achive?

Colun2 id one field?

Dropdown field have values "-","1","2","3","4","5" so what is "Item1"?

Why use radio buttons if you are not making them mutually exclusive, you can use checkboxes instead.

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
Explorer ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

I've created a basic example that is a simplified version. My form has many more items(playground equipment).

The value gets adjusted based on the type of area. There is a possibility that one of the items doesn't exist in the area and therefore would not require a calculation. I haven't finished scripting the rest of the table.

 

https://drive.google.com/file/d/1W43q_sSUzXUGV9de6jAtBgWu_vPRL-JA/view?usp=sharing

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 ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

You've found a clever solution. 

Here is the additon for Item1, assuming that is the actual field name.

 

if(this.getField("Item1").value != "-")
   event.value = oVals[getField("RadioSet").valueAsString];
else
   event.value = ""; 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Explorer ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

Thank you Thom! Do I apply this to the beginning of the custom calculation?

if(this.getField("Item1").value != "-")
event.value = oVals[getField("RadioSet").valueAsString];
else
event.value = "";

ar oVals = {

"Off" : "",

"Radio1" : 4,

"Radio2" : 5,

"Radio3" : 3,

};

event.value = oVals[getField("RadioSet").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
Explorer ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

Oops, I had an extra line. It works adding to what you provided Thom in the custom calculation:

if(this.getField("Item1").value != "-")
event.value = oVals[getField("RadioSet").valueAsString];
else
event.value = "";

ar oVals = {

"Off" : "",

"Radio1" : 4,

"Radio2" : 5,

"Radio3" : 3,

};

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 ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

LATEST

The oVals definition needs to be the first thing in the script, followed by the "if" condition and calculation.

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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