Skip to main content
Participant
May 22, 2024
Question

Please help, I with javascript for a checkbox

  • May 22, 2024
  • 2 replies
  • 223 views

I am using the script below but it only runs if I check and then uncheck the box.  Obviously I want the script to run when I check the box.  Also, I want the "Previous Employer Name" field to clear when the box is unchecked.

 

Any help would be appreciated.

 

if (event.target.value!="Yes") {
this.getField("Previous Employer Name").value = this.getField("Company NameRow1").valueAsString;
this.getField("Address 1_2").value = this.getField("Company AddressRow1").valueAsString;
}

 

 

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
May 22, 2024

There is no "obviously" in programming. You have to explicitly layout exactly what you want to happen, and don't want to happen. Computers don't do nuance and innuendo. 

For example, I'm assuming that the script you posted is a MouseUp script on the checkbox, but you didn't specify, so I don't really know.  If it's not a MouseUp script, then any suggestions I make won't work. You must be explicit about the details. 

 

Here's an updated script that will set and reset the values, if my assumptions are correct.  

 

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

    // this code runs when the checkbox is checked
    this.getField("Previous Employer Name").value = this.getField("Company NameRow1").valueAsString;
    this.getField("Address 1_2").value = this.getField("Company AddressRow1").valueAsString;
}

else{

    // This code runs when the checkbox is unchecked

    this.getField("Previous Employer Name").value = "";

}

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
May 22, 2024

Try this:

if (event.target.value=="Yes") {