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

When a checkbox is checked insert text into another field

New Here ,
Apr 13, 2016 Apr 13, 2016

Hi there,

I know that there have been a lot of other thread like this one but for some reason my code isn't working.  I'm trying to have text inserted into a field when a check box is checked.  Can you please please help.

For a mouse up event:

    var dateCheckbox = this.getField("Date or");  //checkbox

    var detailField = this.getField("Expiration Detail");  //field

  

     

// if the "date or" box is checked than change the Expiration Detail to "Hello"

    if (dateCheckbox.value == "Yes") { 

        detailField.value = "Hello";    

    } 

TOPICS
Acrobat SDK and JavaScript
4.0K
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

correct answers 1 Correct answer

Community Expert , Apr 13, 2016 Apr 13, 2016

Which mouse-up event are you using? In general, when you try to trigger something based on a checkbox selection, you should also take care of the unchecked value. Also, the export value of a checkbox can be modified, so it's usually a better approach to check for value != "Off", because "Off" will always be used for the unchecked case.

Try the following as the mouse-up event of the "Date or" checkbox:

var detailField = this.getField("Expiration Detail");  //field

if (event.target.value != "Off")

...
Translate
Community Expert ,
Apr 13, 2016 Apr 13, 2016

Which mouse-up event are you using? In general, when you try to trigger something based on a checkbox selection, you should also take care of the unchecked value. Also, the export value of a checkbox can be modified, so it's usually a better approach to check for value != "Off", because "Off" will always be used for the unchecked case.

Try the following as the mouse-up event of the "Date or" checkbox:

var detailField = this.getField("Expiration Detail");  //field

if (event.target.value != "Off") {

    detailField.value = "Hello";

}

else {

    detailField.value = "";

}

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
New Here ,
Apr 13, 2016 Apr 13, 2016

That works perfectly!!!

Thank you so much for your time.  I really appreciate it.

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 ,
Sep 06, 2020 Sep 06, 2020

Hi Karl_Heinz_Kremer,

 

How can I used your scripting for multiple text fields? For example, if Checkbox1 is checked, Textfield1 and Textfield2 auto-populates "N/A"

 

Thank you in advance.

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 ,
Sep 06, 2020 Sep 06, 2020

Use this as MouseUp event of CheckBox:

var t1 = this.getField("Textfield1");
var t2 = this.getField("Textfield2");
if(event.target.value != "Off"){
t1.value = "N/A"
t2.value = "N/A";}
else if(event.target.value == "Off"){
t1.value = ""
t2.value = "";}

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
New Here ,
Aug 13, 2023 Aug 13, 2023

Hi can any one help

If check box 'A' and checkbox 'B' both are checked then it should print value 'yes' else 'no'

 

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 ,
Aug 13, 2023 Aug 13, 2023

As the custom calculation script of the text field enter this:

event.value = (this.getField("A").valueAsString=="Off" || this.getField("B").valueAsString=="Off") ? "no" : "yes";

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 ,
Aug 21, 2023 Aug 21, 2023

What script would I use for the following:

Check box 1 = PDF

Check box 2 = Divorce Decree

Check box 3 = Birth Certificate

 

When all boxes are checked, the text is put into the same text box, or if only 2 boxes are checked, only the 2 texts are included in the text box.

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 ,
Aug 21, 2023 Aug 21, 2023

Do you want to display the text in a single line? If so, should they be separated by something, like a comma or a semi-colon? Or should each text be on a separate line in a multi-line field?

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 ,
Aug 21, 2023 Aug 21, 2023

Single line please!

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 ,
Aug 21, 2023 Aug 21, 2023

You can use this code as the custom Calculation script of the final text field, then:

 

var fields = ["Check box 1", "Check box 2", "Check box 3"];
var texts = ["PDF", "Divorce Decree", "Birth Certificate"];
var selectedTexts = [];
for (var i=0; i<fields.length; i++) {
	if (this.getField(fields[i]).valueAsString!="Off") selectedTexts.push(texts[i]);
}
event.value = selectedTexts.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 ,
Aug 22, 2023 Aug 22, 2023

That worked perfectly!  Thank you so much!

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 ,
Aug 22, 2023 Aug 22, 2023

Another question...same thing, but I want some followed by a comma and some that I don't.  Such as when Checkbox for "What was received" is toggled it adds "Rec'd" followed by no comma and then the others are selected which are followed by a comma.

Screenshot 2023-08-22 073320.jpgexpand image

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 ,
Aug 23, 2023 Aug 23, 2023

@try67 please see my follow up question above!  Thank you so much for the help!

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 ,
Aug 23, 2023 Aug 23, 2023

Can you post the code, or the file?

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 ,
Aug 23, 2023 Aug 23, 2023

This is what I currently have but I want some followed by just a space and some followed by a period:

 

var fields = ["CB37", "CB1", "CB2", "CB3", "CB4", "CB5", "CB6", "CB7", "CB8", "CB9", "CB10", "CB11", "CB12", "CB13", "CB14", "CB38", "CB15", "CB16", "CB17", "CB18", "CB19", "CB20", "CB21", "CB22", "CB23", "CB39", "CB24", "CB25", "CB27", "CB29", "CB30", "CB31", "CB32", "CB33", "CB42", "CB35"];
var texts = ["Rec'd", "PDF", "DD", "BC", "MC", "SSN Card", "ID", "Med ID", "Court Order", "Adoption Decree", "COB Docs", "DP Docs", "Kaiser EF", "COA", "FILL IN OTHER", "Updated", "Address", "Email", "Phone", "Name", "Gender", "Marital Status", "DOB", "Dep(s)", "FILL IN OTHER", "Mem", "Dep", "EIR sent for", "DD", "BC", "MC", "Adoption Decree", "FILL IN OTHER", "FILL IN OTHER LETTER SENT", "Doc(s) sent to scan"];
var selectedTexts = [];
for (var i=0; i<fields.length; i++) {
if (this.getField(fields[i]).valueAsString!="Off") selectedTexts.push(texts[i]);
}
event.value = selectedTexts.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
Community Expert ,
Aug 23, 2023 Aug 23, 2023

This description is a bit too vague. You need to clearly define which fields should be followed by a space, and which by a period. Maybe include it in the actual strings in the texts array, and change the delimiter under the join command to a blank string.

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
New Here ,
Jun 09, 2024 Jun 09, 2024
LATEST

Can someone help me with google sheets

 

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