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

Summary section that shows all selected answers in multiple list boxes and text field

Community Beginner ,
Apr 30, 2019 Apr 30, 2019

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.

TOPICS
PDF forms
3.6K
Translate
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 ,
Apr 30, 2019 Apr 30, 2019

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.

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

Translate
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 ,
Apr 30, 2019 Apr 30, 2019

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.

Translate
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 ,
Apr 30, 2019 Apr 30, 2019

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;

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

Translate
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 ,
Apr 30, 2019 Apr 30, 2019

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..

Translate
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 ,
Apr 30, 2019 Apr 30, 2019

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.

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

Translate
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 ,
Apr 30, 2019 Apr 30, 2019

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?

Translate
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 ,
Apr 30, 2019 Apr 30, 2019

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;

}

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

Translate
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 ,
Apr 30, 2019 Apr 30, 2019

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.

Translate
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 ,
Apr 30, 2019 Apr 30, 2019

Yes, this requires testing the field values before adding them into the string.

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

Translate
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 ,
Apr 30, 2019 Apr 30, 2019

Do you just add something to the existing summary field script? Can you help me with the script? It would be a big help.

Translate
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 ,
Apr 30, 2019 Apr 30, 2019

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

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

Translate
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 ,
May 01, 2019 May 01, 2019

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..

Translate
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 01, 2019 May 01, 2019

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.

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

Translate
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 ,
May 01, 2019 May 01, 2019
LATEST

Yup. Thanks for your time.

Translate
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