Skip to main content
Participant
April 13, 2016
Answered

When a checkbox is checked insert text into another field

  • April 13, 2016
  • 5 replies
  • 4848 views

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

    } 

This topic has been closed for replies.
Correct answer Karl Heinz Kremer

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

}

5 replies

Participant
June 10, 2024

Can someone help me with google sheets

 

Inspiring
August 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.

try67
Community Expert
Community Expert
August 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?

Inspiring
August 21, 2023

Single line please!

Participant
August 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'

 

try67
Community Expert
Community Expert
August 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";

Inspiring
September 6, 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.

Nesa Nurani
Community Expert
Community Expert
September 7, 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 = "";}

Karl Heinz  Kremer
Community Expert
Karl Heinz KremerCommunity ExpertCorrect answer
Community Expert
April 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 = "";

}

Participant
April 13, 2016

That works perfectly!!!

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