Skip to main content
lilleem89
Participating Frequently
November 2, 2018
Answered

MultipleCheckboxes to populate 1 textbox

  • November 2, 2018
  • 1 reply
  • 1110 views

Hi,

I am really new to javascript so bear with me. I am making a form where I have many checkboxes all named "checkbox 1" and so on (like 30 or more) that I have assigned export values (such as "red", "blue", "green"..etc).  I need all of those checkboxes to populate their given export values to a single textbox(textbox 1) when checked and to remove the value when unchecked. also I need to have the values separated by commas when they are populated to the textbox and to be able to manually type in the text box as well. Please help

This topic has been closed for replies.
Correct answer try67

Use this code as the custom calculation script of your text field:

var values = [];

for (var i=1; i<=30; i++) {

    var fname = "checkbox "+i;

    var f = this.getField(fname);

    if (f==null) {

        console.println("Error! Can't find: " + fname);

        continue;

    }

    if (f.valueAsString!="Off") values.push(f.valueAsString);

}

event.value = values.join(", ");

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 2, 2018

Use this code as the custom calculation script of your text field:

var values = [];

for (var i=1; i<=30; i++) {

    var fname = "checkbox "+i;

    var f = this.getField(fname);

    if (f==null) {

        console.println("Error! Can't find: " + fname);

        continue;

    }

    if (f.valueAsString!="Off") values.push(f.valueAsString);

}

event.value = values.join(", ");

lilleem89
lilleem89Author
Participating Frequently
November 4, 2018

I also want to have a text box(Text4) to populate the same text box that check boxes populate to. How do I add that to the above script ?

try67
Community Expert
Community Expert
November 4, 2018

I don't follow what you mean...