Skip to main content
Inspiring
Mar 6, 2017 5:28 PM UTC
Answered

How can I make check boxes generate paragraphs of text

Hi,

How can i make check boxes generate text?

I have 9 check boxes, each with their own individual Export Value. (The Export Value is a paragraph of text.)

I would like it so when people choose the check boxes they need, the result is shown in a text field, so I'm trying to write a custom calculation script.

My Checkboxes are called "Check Box 1" "Check Box 2" etc, and the results box is called "Strength results".

I can get it so I get all the text in one line, and the the word "Off" for each checkbox that isn't checked however I'm wanting:

Check Box 1 text (or which ever is selected)

Line break \n

Check Box 2 text (or which ever is selected)

Line break \n

Check Box 3 text (or which ever is selected)

Can you help?

Thanks

This topic is closed to new replies. Start a new post to keep the conversation going.
Joel Geraci
Joel GeraciCorrect answer
Community Expert
Mar 6, 2017 5:38 PM UTC

Rename your checkboxes to "CheckBox.1", CheckBox.2" etc. then use the following code as your calculation in the field where you want the paragraphs to appear. "\n\n" will put an additional line break between the paragraphs.

var paras = [];

var fields = this.getField( "CheckBox" ).getArray();

// sort by name

fields.sort( function( a, b ) {

     var nameA = a.name.toUpperCase(); // ignore upper and lowercase

     var nameB = b.name.toUpperCase(); // ignore upper and lowercase

     if ( nameA < nameB ) {

          return -1;

     }

     if ( nameA > nameB ) {

          return 1;

     }

     // names must be equal

     return 0;

} );

for ( var i = 0; i < fields.length; i++ ) {

     var field = fields[ i ];

     if ( field.isBoxChecked( 0 ) ) {

          paras.push( field.value )

     }

}

event.value = paras.join( "\n\n " )

4 replies

Inspiring
Mar 7, 2017 10:37 AM UTC

Another question if anyone knows the answer (not as pressing as the other, hence not creating another thread).

We can set the Export Value of check box to be text easily within the properties menu, however, how can you insert a line break in a body of text in the export value? So you can export multiple paragraphs, as opposed to one...Any ideas?

Thanks

Translate
try67
Community Expert
Community Expert
Mar 7, 2017 10:43 AM UTC

You can only do that using a script, but it's not recommended. If you really want to do it I would recommend replacing the line-breaks with some kind of place-holder character, like the pipe symbol ("|"), and then you'll just need to replace it back when applying the value to your multiline text field.

Translate
Joel Geraci
Community Expert
Joel GeraciCommunity ExpertCorrect answer
Community Expert
Mar 6, 2017 5:38 PM UTC

Rename your checkboxes to "CheckBox.1", CheckBox.2" etc. then use the following code as your calculation in the field where you want the paragraphs to appear. "\n\n" will put an additional line break between the paragraphs.

var paras = [];

var fields = this.getField( "CheckBox" ).getArray();

// sort by name

fields.sort( function( a, b ) {

     var nameA = a.name.toUpperCase(); // ignore upper and lowercase

     var nameB = b.name.toUpperCase(); // ignore upper and lowercase

     if ( nameA < nameB ) {

          return -1;

     }

     if ( nameA > nameB ) {

          return 1;

     }

     // names must be equal

     return 0;

} );

for ( var i = 0; i < fields.length; i++ ) {

     var field = fields[ i ];

     if ( field.isBoxChecked( 0 ) ) {

          paras.push( field.value )

     }

}

event.value = paras.join( "\n\n " )

Translate
Inspiring
Mar 6, 2017 6:59 PM UTC

Amazing!! this is perfect.

Thank you so much Joel

Translate