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

Concatenate text

Explorer ,
Nov 28, 2024 Nov 28, 2024

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
1.1K
Translate
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
3 ACCEPTED SOLUTIONS
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(",") : "";

View solution in original post

Translate
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

Change:

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

View solution in original post

Translate
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
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") : "";

View solution in original post

Translate
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 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(",") : "";
Translate
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

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

Translate
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

Change:

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

Translate
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

Thanks.

Translate
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

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

Translate
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
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") : "";
Translate
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