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

Code check for hiding a button

New Here ,
Oct 08, 2025 Oct 08, 2025

Hello again everyone.

I have the code below which is a button to generate an email and also make a check box visible on a form going out to a customer.  I have an employee signature box which flattens the form except for this button and the customer signature fields.  The code  is in a mouse up javascript within the action tab of the button. 

The code works in the fact it generates the email and makes the check box visible when attached to the email message, however no matter where I locate the code to hide the button its still visible when the PDF is opened from the received email.  Can anyone suggest how I can make this work as intended please

try {
    var cb = this.getField("yes");
    if (cb) {
        cb.display = display.visible; 
        cb.value = "Off"; 
    }
 
    this.display = display.hidden;
 
    var cToAddr = this.getField("8") ? this.getField("8").valueAsString : "";
    var cCustomer = this.getField("4") ? this.getField("4").value : "";
    var cMake = this.getField("12") ? this.getField("12").value : "";
    var cUnit = this.getField("14") ? this.getField("14").value : "";
    var cSubLine = "Machine Service Contract" + " - " + cCustomer + " - " + cMake + "   " + cUnit;
 
    var cBody = "Please find attached the Service Contract for the above machine." + 
                " Please make sure to read the terms fully before signing.";
 
    this.mailDoc({
        bUI: true,
        cTo: cToAddr,
        cCc: cCc,
        cSubject: cSubLine,
        cMsg: cBody
    });
 
} catch (e) {
    app.alert("Error: " + e.message); 
}
------------------------------------------------------------------------
[Sighs] - Trying my hardest to learn all this
TOPICS
JavaScript , PDF forms
113
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
1 ACCEPTED SOLUTION
Community Expert ,
Oct 08, 2025 Oct 08, 2025

So is it this line that is supposed to hide the button?

this.display = display.hidden;

 

In the button context, the "this" keyword is the document object. Seems like it aught to be the button object, since that's where the script is placed, but it's not.  The button object is available through the event object.

Use this code to hide the button. 

 

event.target.display = display.hidden;

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

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 ,
Oct 08, 2025 Oct 08, 2025

So is it this line that is supposed to hide the button?

this.display = display.hidden;

 

In the button context, the "this" keyword is the document object. Seems like it aught to be the button object, since that's where the script is placed, but it's not.  The button object is available through the event object.

Use this code to hide the button. 

 

event.target.display = display.hidden;

 

 

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
New Here ,
Oct 09, 2025 Oct 09, 2025

Perfect Thom,

Thank you very muh

------------------------------------------------------------------------
[Sighs] - Trying my hardest to learn all this
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 ,
Oct 09, 2025 Oct 09, 2025
LATEST

The Acrobat JavaScript model, much like Acrobat, is not obvious. Got lots of non-standard quirks. 

 

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