Fill text field with checkboxes

Community Beginner ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

I have text field and 3 checkboxes c1,c2 and c3
text field is multiline, I want to have static text and then if checkbox is checked to add line of text
or remove if checkbox is unchecked. Is that possible?

TOPICS
JavaScript

Views

234

Likes

Translate

Translate

Report

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

correct answers 2 Correct Answers

Adobe Community Professional , Feb 20, 2021 Feb 20, 2021
Put this code in text field as 'custom calculation script': var text = "Static text goes here"; if(this.getField("c1").valueAsString != "Off") text += "\nText for c1 goes here"; if(this.getField("c2").valueAsString!= "Off") text += "\nText for c2 goes here"; if(this.getField("c3").valueAsString!= "Off") text += "\nText for c3 goes here"; event.value = text;

Likes

Translate

Translate
Adobe Community Professional , Feb 21, 2021 Feb 21, 2021
Sure you can use like this: var text = "Static text goes here"; if(this.getField("g1").valueAsString == "Choice1") text += "\nText for choice1 goes here"; if(this.getField("g1").valueAsString == "Choice2") text += "\nText for choice2 goes here"; if(this.getField("g1").valueAsString == "Choice3") text += "\nText for choice3 goes here"; event.value = text;

Likes

Translate

Translate
Adobe Community Professional ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

Put this code in text field as 'custom calculation script':
var text = "Static text goes here";
if(this.getField("c1").valueAsString != "Off")
text += "\nText for c1 goes here";
if(this.getField("c2").valueAsString!= "Off")
text += "\nText for c2 goes here";
if(this.getField("c3").valueAsString!= "Off")
text += "\nText for c3 goes here";
event.value = text;

Likes

Translate

Translate

Report

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 ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

Thank you so much.

Likes

Translate

Translate

Report

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 ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

Hi, I decided I wanna try another aproach and use 3 radio buttons named g1 with Choice1,2,3
Can i adapt your code to do that?

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Feb 21, 2021 Feb 21, 2021

Copy link to clipboard

Copied

Sure you can use like this:
var text = "Static text goes here";
if(this.getField("g1").valueAsString == "Choice1")
text += "\nText for choice1 goes here";
if(this.getField("g1").valueAsString == "Choice2")
text += "\nText for choice2 goes here";
if(this.getField("g1").valueAsString == "Choice3")
text += "\nText for choice3 goes here";
event.value = text;

Likes

Translate

Translate

Report

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 01, 2021 Apr 01, 2021

Copy link to clipboard

Copied

Is there a way of doing this checkbox merging into a textfield using the Checkboxes Export Value rather than writing the "Text for c1 goes here" in the code?

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 01, 2021 Apr 01, 2021

Copy link to clipboard

Copied

Yes, you can use it like this:

var text = "Static text goes here";
if(this.getField("c1").valueAsString != "Off")
text += "\n"+this.getField("c1").valueAsString;
if(this.getField("c2").valueAsString!= "Off")
text += "\n"+this.getField("c2").valueAsString;
if(this.getField("c3").valueAsString!= "Off")
text += "\n"+this.getField("c3").valueAsString;
event.value = text;

Likes

Translate

Translate

Report

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 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Love ya work Nesa!

Likes

Translate

Translate

Report

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 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

Is it possible to adapt this script so that rather than code in individual checkbox values (c1,c2,c3) I could group them and then use group1 for group1.c1, group1.c2, group1.c3 checkboxes?  If not, is there an alternative way of doing so?

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

You could store values of c1,c2,c3 in variable and then call it when needed.

Likes

Translate

Translate

Report

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 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

LATEST

Sorry Nesa, I'm new at writing JS.  Could you please show me how to do this?

Likes

Translate

Translate

Report

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