Copy link to clipboard
Copied
I have multiple dropdown boxes, each having seven options. Next to each dropdown box there are "Yes" and "No" radio buttons. The user needs to select one of the options from each dropdown and then use a radio button to select "Yes" or "No". If "Yes" is selected, I need the option from the dropdown selection to populate in a text field, If "No is selected, then nothing needs to happen.
Is this possible? If so, is it possible to have just one text field with all of the "Yes" selections?
Copy link to clipboard
Copied
You've inserted multiple errors into the code when you edited it, which would also trigger error messages to appear in the JS Console.
Use this, instead:
var values = [];
for (var i=1; i<=12; i++) {
if (this.getField("Choice"+i).valueAsString=="Yes") {
values.push(this.getField("Dropdown"+i).valueAsString);
}
}
event.value = values.join(", ");
Copy link to clipboard
Copied
When you say "nothing needs to happen", do you mean the text field should maintain its value, no matter what it is? And what are the names of the fields involved?
Copy link to clipboard
Copied
That is correct. When the "No" radio button is selected, the value of the selected option in the dropdown does not populate in the text field.
The dropdown fields are "dropdown1", "dropdown2", "dropdown3", etc. The radio buttons are "choice1", "choice2", choice3, etc. The text field is "summary".
For example, the user selects the "English" option from dropdown1 and then they select "Yes" from the choice1 radio button options, "English" populates in the text field summary. If the user selects "Math" from dropdown2 and then selects "Yes" from the choice2 radio buttons, then "Math" would also appear in the text field summary. If on dropdown3 the user selects "Science" and then selects the "No" option from the choice3 radio, then "Science" does not appear in the summary text field, but "English" and "Math" would still be in the summary text field. The "No" option of the radio button only means that the selected option in the dropdown does not get populated in the summary text field.
Copy link to clipboard
Copied
But should the user be able to manually change the value of the text field, even if some of the radio-buttons are ticked as Yes?
Copy link to clipboard
Copied
No, the user only has the choices in the dropdown. The text field would be read only. If they select "Yes" the dropdown option appears in the text field. If they change their mind and select "No" for a dropdown they previously answered "Yes" to, the text for that answer would not stay in the text field.
Copy link to clipboard
Copied
OK, then you can use something like this code as the custom Calculation script of the first text field, for example:
event.value = this.getField("choice1").valueAsString=="Yes" ? this.getField("dropdown1").valueAsString : "";
Copy link to clipboard
Copied
This works great! Is there a way to have multiple "Yes" answers populate the choice value in the same text field as a list or do I need to have a separate text field for each possible "Yes" response?
Copy link to clipboard
Copied
Something like this?
var values = [];
for (var i=1; i<=3; i++) {
if (this.getField("choice"+i).valueAsString=="Yes") {
values.push(this.getField("dropdown"+i).valueAsString);
}
}
event.value = values.join(", ");
Edited: Code fixed
Copy link to clipboard
Copied
Change 'values' to array.
Copy link to clipboard
Copied
Correct, thank you.
Copy link to clipboard
Copied
I've tried a few different variations with replacing 'values' with array and can't seem to get it to work. What am I missing?
Copy link to clipboard
Copied
What happens when you use it, exactly?
Copy link to clipboard
Copied
The word from the dropdown menu does not appear in the "Summary" text field. The JavaScript Debugger indicates "TypeError: this.getField(...) is null
3:Field:Calculate
TypeError: this.getField(...) is null
3:Field:Calculate
TypeError: this.getField(...) is null
3:Field:Calculate"
Copy link to clipboard
Copied
This means one of the field names you specified is incorrect. Double-check everything, including upper/lower-case letters, spaces, etc. Even a single character off will cause it to malfunction.
Copy link to clipboard
Copied
I'm still new at this so I think that there is some other basic thing I am missing. I put the formula below in the previously mentioned "Summary" box where I want all the "Yes" answers to go, double checked the names of the fields that go into the formula, and tried different variations of the formula.
var array = [];
for (var i=1; i<=3; i++) {
if (this.getField("choice"+i).valueAsString=="Yes") {
values.push(this.getField("dropdown"+i).valueAsString);
}
}
event.value = values.join(", ");
Copy link to clipboard
Copied
Then you'll need to share the file for further help.
Copy link to clipboard
Copied
Change the first line back to what I posted above (after the edit).
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You've inserted multiple errors into the code when you edited it, which would also trigger error messages to appear in the JS Console.
Use this, instead:
var values = [];
for (var i=1; i<=12; i++) {
if (this.getField("Choice"+i).valueAsString=="Yes") {
values.push(this.getField("Dropdown"+i).valueAsString);
}
}
event.value = values.join(", ");
Copy link to clipboard
Copied
You are awesome! Thank you so much!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now