When a checkbox is checked insert text into another field

New Here ,
Apr 13, 2016 Apr 13, 2016

Copy link to clipboard

Copied

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

Views

476

Likes

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

Adobe Community Professional , 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") ...

Likes

Translate

Translate
Adobe Community Professional ,
Apr 13, 2016 Apr 13, 2016

Copy link to clipboard

Copied

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 = "";

}

Likes

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

Copy link to clipboard

Copied

That works perfectly!!!

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

Likes

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

Copy link to clipboard

Copied

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.

Likes

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

Copy link to clipboard

Copied

LATEST

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 = "";}

Likes

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