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

MultipleCheckboxes to populate 1 textbox

Community Beginner ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

668

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 1 Correct answer

Community Expert , Nov 02, 2018 Nov 02, 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(", ");

Votes

Translate

Translate
Community Expert ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

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

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 ,
Nov 04, 2018 Nov 04, 2018

Copy link to clipboard

Copied

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 ?

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 04, 2018 Nov 04, 2018

Copy link to clipboard

Copied

I don't follow what you mean...

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 ,
Nov 04, 2018 Nov 04, 2018

Copy link to clipboard

Copied

I have the checkboxes populating to "textbox 1" as discussed above. Now I want a textbox that I have named "textbox 4" to populate whatever I type in it to "textbox 1" as well.  So in the end the checkboxes AND "textbox 4" will populate to "textbox 1".

Does that make sense?

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 04, 2018 Nov 04, 2018

Copy link to clipboard

Copied

Change the name of "textbox 4" to "textbox 1" and it will happen automatically.

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 ,
Nov 04, 2018 Nov 04, 2018

Copy link to clipboard

Copied

That won't work because the check boxes that populate to "textbox 1" then populate to "textbox 4" if the textboxes have the same name and I don't want the check boxes to populate to both textboxes....Just "textbox 1"

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 04, 2018 Nov 04, 2018

Copy link to clipboard

Copied

But you want to copy the value from "textbox 1" to "textbox 4", right? So what's the difference?

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 04, 2018 Nov 04, 2018

Copy link to clipboard

Copied

Sorry, I understand now what you want to do.

Add this line before the last line of the previous code:

if (this.getField("textbox 4").valueAsString!="") values.push(this.getField("textbox 4").valueAsString);

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 ,
Nov 04, 2018 Nov 04, 2018

Copy link to clipboard

Copied

It's still populating the checkbox values that are supposed to only go to "textbox 1" to "textbox 4".  It's Literally just copying "textbox 1" and putting it into "textbox 4"

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 ,
Nov 04, 2018 Nov 04, 2018

Copy link to clipboard

Copied

I just want what is typed into "textbox 4" to populate to "textbox 1" in addition to the checkboxes that already populate to "textbox 1"

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 ,
Nov 04, 2018 Nov 04, 2018

Copy link to clipboard

Copied

I got it to work! thank you very much I appreciate it

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 ,
Nov 04, 2018 Nov 04, 2018

Copy link to clipboard

Copied

I got it to work! 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
Community Beginner ,
Mar 08, 2019 Mar 08, 2019

Copy link to clipboard

Copied

In this example, instead of separating by a comma, how do I start a new text line for the next value?

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 ,
Mar 09, 2019 Mar 09, 2019

Copy link to clipboard

Copied

LATEST

Replace:

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