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

Concatenate text

Explorer ,
Nov 28, 2024 Nov 28, 2024

Copy link to clipboard

Copied

I have five text fields (Text1 to Text5) and five corresponding checkboxes (Check Box1 to Check Box5). I need to create a script such that when a checkbox is selected, the value of the corresponding text field is displayed in a separate field. If multiple checkboxes are selected, the values of the associated text fields should be concatenated and displayed, separated by commas. Could you advise on how to implement this functionality using a custom script?

TOPICS
JavaScript

Views

139

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 3 Correct answers

Community Expert , Nov 28, 2024 Nov 28, 2024

Use this as custom calculation script in a field where you want to show text:

var txt = [];
for(var i=1; i<=5; i++){
 var c = this.getField("Check Box"+i).valueAsString;
 var t = this.getField("Text"+i).valueAsString;
 
 if(c !== "Off")
  txt.push(t);}

event.value = txt.length ? txt.join(",") : "";

Votes

Translate

Translate
Community Expert , Nov 30, 2024 Nov 30, 2024

Change:

join(",") with join("\n")

Votes

Translate

Translate
Community Expert , Dec 06, 2024 Dec 06, 2024

Try this:

if (typeof orderArray === "undefined") {
 var orderArray = [];}

var txt = [];

for (var i=1; i<=5; i++) {
 var checkbox = this.getField("Check Box"+i).valueAsString;
 var text = this.getField("Text"+i).valueAsString;

 if (checkbox !== "Off") {
  if (orderArray.indexOf(i) === -1) {
   orderArray.push(i);}} 
 else {
  var index = orderArray.indexOf(i);
  if (index !== -1) {
   orderArray.splice(index, 1);}}}

for (var idx of orderArray) {
 txt.push(this.getField("Text" + idx).valueAsSt
...

Votes

Translate

Translate
Community Expert ,
Nov 28, 2024 Nov 28, 2024

Copy link to clipboard

Copied

Use this as custom calculation script in a field where you want to show text:

var txt = [];
for(var i=1; i<=5; i++){
 var c = this.getField("Check Box"+i).valueAsString;
 var t = this.getField("Text"+i).valueAsString;
 
 if(c !== "Off")
  txt.push(t);}

event.value = txt.length ? txt.join(",") : "";

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 ,
Nov 30, 2024 Nov 30, 2024

Copy link to clipboard

Copied

I changed field to multiline, how to show each value in separate row?

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 ,
Nov 30, 2024 Nov 30, 2024

Copy link to clipboard

Copied

Change:

join(",") with join("\n")

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 ,
Nov 30, 2024 Nov 30, 2024

Copy link to clipboard

Copied

Thanks.

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 ,
Dec 06, 2024 Dec 06, 2024

Copy link to clipboard

Copied

Is it possible to add text by order it is checked?

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 ,
Dec 06, 2024 Dec 06, 2024

Copy link to clipboard

Copied

LATEST

Try this:

if (typeof orderArray === "undefined") {
 var orderArray = [];}

var txt = [];

for (var i=1; i<=5; i++) {
 var checkbox = this.getField("Check Box"+i).valueAsString;
 var text = this.getField("Text"+i).valueAsString;

 if (checkbox !== "Off") {
  if (orderArray.indexOf(i) === -1) {
   orderArray.push(i);}} 
 else {
  var index = orderArray.indexOf(i);
  if (index !== -1) {
   orderArray.splice(index, 1);}}}

for (var idx of orderArray) {
 txt.push(this.getField("Text" + idx).valueAsString);}

event.value = txt.length ? txt.join("\n") : "";

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