Javascript/LiveCycle: Function to search for checked boxes, then output to text field

61 Views Asked by At

I'm pretty new to Javascript and need a little help. Currently I'm working on a rather complex form in LiveCycle for a very specific type of report. The first page is a face sheet which collects a bunch of information, and the subsequent pages automates that information into a narrative style report which requires minimal extra user input.

At the end of the first page I have a series of 7 checkboxes representing 7 different categories [for demonstrative purposes, lets say the categories are Apples, Oranges, Bananas, Pears, Mangos, Apricots and Berries].

At the very end of the report I have a specific preworded statement with a text field in the middle of it. "I really like to eat [ text field ], and fruits are the best thing ever."

What I am trying to figure out how to accomplish is to script the value of that text field as a string to be the selected category or any variation of multiple selected categories. The categories have an determined order to them.

"I really like to eat [ Apples ], and fruits are the best thing ever."

||

"I really like to eat [ Apples, and Bananas ], and fruits are the best thing ever."

||

"I really like to eat [ Apples, Bananas, and Pears ], and fruits are the best thing ever."

I know it will involve using a loop to determine which boxes are selected, then concatenate the selections using grammatical separators. I just don't know how to code it! Or maybe I'm thinking about it the wrong way. Any help would be appreciated!

1

There are 1 best solutions below

5
Alison Moura On

You can use something like: document.querySelectorAll("input[type=checkbox]:checked") this will return the array (NodeList) of checked checkboxes.

See here one possible solution for the problem that what you sad: https://jsfiddle.net/alisonmoura/gq1eaoLd/4/

See if it helps ;D