Copy link to clipboard
Copied
I have a form that contains different categories, subcategories and a summary section.
Per item, users must choose 1 from 3 radio buttons (A,R & N/A), and select an option in a list box. Users can select multiple items in the list box if they need to.
The form looks like this.
I want the Summary box to contain the category name, sub category name, selected radio button option, selected items and the general comments section.
I know the script on how to populate a textbox with the selected items in a list box, but that's just for one item only and not multiple list boxes.
Here's how I want the summery box to look like based on the selected items in the image..
Building
Item 1 - A
Detailed Item List: B, C, D
Item 2 - R
Detailed Item List: 3, 4
Item 3 - R
Detailed Item List: 9
Mechanical
Item 1 - N/A
Detailed Item List: W, E
Item 2 - A
Detailed Item List: A1, A2
Item 3 - R
Detailed Item List: B2, B3
Plumbing
Item 1 - A
Detailed Item List: C1, C2
Item 2 - R
Detailed Item List: D1
Item 3 - N/A
Detailed Item List: P
General Comments
Sample text.
I'm not sure if this is the easiest way to do this, to use list boxes. Or check boxes is the way to go. I can add all the items and just put check boxes beside every option.
Any suggestions on how to make this happen?
Thank you in advance.
Copy link to clipboard
Copied
So what is the script you have now for only one item?
It looks pretty straight forward. I imagine the complete script is an extension of the one you already have.
Just add up all the text values exported from each group of fields (using the desired formatting) into one string, and place this in the summary text box.
Since each block has an identical set of fields, I'd suggest using a function to create the formatted text for each block, with inputs for each of fields.
Copy link to clipboard
Copied
Here it is.
var v = this.getField("LB1").value;
if (typeof v=="object") event.value = v.join(", ");
else event.value = v.toString();
The thing is this script does not show the category name, subcategory name and the selected radio button. I also do not have an idea on how to add the other subcategories and the remaining categories.
Copy link to clipboard
Copied
You've got a start.
Here's a function to build the basic block of text.
function BuildTextBlock(strItemName, strRadioName, strListName)
{
var strRtn = strItemName + " - " + this.getField(strRadioName).value + "\nDetailed Item List:";
var v = this.getField("LB1").value;
if (typeof v=="object") strRtn += v.join(", ");
else strRtn += v.toString();
return strRtn;
}
// Now call this function for each block, adding the necessary text inbetween
var strSummary;
strSummary = "Building\n" + BuildTextBlock("Item 1", "RadioField1", "LB1") + "\n";
strSummary += BuildTextBlock("Item 2", "RadioField2", "LB2") + "\n";
// ...And repeat until the end
event.value = strSummary;
Copy link to clipboard
Copied
Is this all going to be in the summary text field? I edited the script and I messed up. It did show something but the the result got jumbled.
Here's how it looked like.
Only Plumbing appeared, the radio options are correct however the selected items in the list boxes show the result of Item 1 - Building in all 3 items..
Copy link to clipboard
Copied
Plumbing is the last so I suspect you reassigned at the top of each section, i.e., if you use the "=" operator it overwrites all the other text. The "+=" operator adds onto the existing text. The "=" (assignment operator) is only used for the first text assignment.
Copy link to clipboard
Copied
That's resolved, but the selected items in the list boxes isn't. It still shows the result of item 1 in all the items. Any idea on how to fix this?
Copy link to clipboard
Copied
The problem is the list field name is hard coded in the function. Here's the update for just the function code.
function BuildTextBlock(strItemName, strRadioName, strListName)
{
var strRtn = strItemName + " - " + this.getField(strRadioName).value + "\nDetailed Item List:";
var v = this.getField(strListName).value;
if (typeof v=="object") strRtn += v.join(", ");
else strRtn += v.toString();
return strRtn;
}
Copy link to clipboard
Copied
That's why. I finally got it to work. Last scenario though, if the form is new, is it possible for the summary to be blank instead of showing all the categories, subcategories etc...? And if the user skips answering any of the items, it won't show in the summary? Example the user skipped answering Building- item 2, Building - Item 2 will not show whil the rest of the answered items will reflect.
Copy link to clipboard
Copied
Yes, this requires testing the field values before adding them into the string.
Copy link to clipboard
Copied
Do you just add something to the existing summary field script? Can you help me with the script? It would be a big help.
Copy link to clipboard
Copied
You've already seen how the list value is tested. What you need to do is use the console window to learn the values of the fields when they are in different states, mainly the unselected state, which is what you want to detect. Write code to test for these values in the function. If all the fields are unselected, then return an empty string instead of the values.
Here's a tutorial on the console window.
Free Video Content & Full Listing of Available Videos
Copy link to clipboard
Copied
Thanks for the link and for answering. I have tried since last night to see if I can make it hidden unless answered but still no luck..
Copy link to clipboard
Copied
You actually have to figure out exactly what it is that you want to happen in all the different configurations. What if the radio buttons are selected and not the list, vice versa. And because there is some complexity here this is not a trivial thing to code. This forum is for people want to learn how to code it themselves. If you just want the code written for you, then you need to hire someone.
Copy link to clipboard
Copied
Yup. Thanks for your time.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now