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

Please help, I with javascript for a checkbox

Community Beginner ,
May 22, 2024 May 22, 2024

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

 

 

TOPICS
Windows
236
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 ,
May 22, 2024 May 22, 2024

Try this:

if (event.target.value=="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
Community Expert ,
May 22, 2024 May 22, 2024
LATEST

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

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