Skip to main content
Participant
Apr 13, 2016 1:54 PM UTC
Answered

When a checkbox is checked insert text into another field

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 is closed to new replies. Start a new post to keep the conversation going.
Karl Heinz  Kremer
Karl Heinz KremerCorrect answer
Community Expert
Apr 13, 2016 1:59 PM UTC

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

}

17 replies

Participant
Jun 10, 2024 12:46 AM UTC

Can someone help me with google sheets

 

Translate
Inspiring
Aug 21, 2023 8:20 PM UTC

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
try67
Community Expert
Community Expert
Aug 21, 2023 8:30 PM UTC

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
Inspiring
Aug 21, 2023 8:31 PM UTC

Single line please!

Translate
Participant
Aug 13, 2023 10:29 AM UTC

Hi can any one help

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

 

Translate
try67
Community Expert
Community Expert
Aug 13, 2023 10:35 AM UTC

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
Inspiring
Sep 6, 2020 10:43 PM UTC

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
Nesa Nurani
Community Expert
Community Expert
Sep 7, 2020 4:56 AM UTC

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
Karl Heinz  Kremer
Community Expert
Karl Heinz KremerCommunity ExpertCorrect answer
Community Expert
Apr 13, 2016 1:59 PM UTC

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
Participant
Apr 13, 2016 2:05 PM UTC

That works perfectly!!!

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

Translate