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?
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(",") : "";
Change:
join(",") with join("\n")
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
...
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(",") : "";
Copy link to clipboard
Copied
I changed field to multiline, how to show each value in separate row?
Copy link to clipboard
Copied
Change:
join(",") with join("\n")
Copy link to clipboard
Copied
Thanks.
Copy link to clipboard
Copied
Is it possible to add text by order it is checked?
Copy link to clipboard
Copied
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") : "";