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

Fill text field with checkboxes

Explorer ,
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

1.0K

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

Community Expert , 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;

Votes

Translate

Translate
Community Expert , 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;

Votes

Translate

Translate
Community Expert ,
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;

Votes

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

Copy link to clipboard

Copied

Thank you so much.

Votes

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
Explorer ,
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?

Votes

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 Expert ,
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;

Votes

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?

Votes

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 Expert ,
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;

Votes

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!

Votes

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?

Votes

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

Votes

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?

Votes

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