Skip to main content
Known Participant
October 8, 2025
Answered

Code check for hiding a button

  • October 8, 2025
  • 1 reply
  • 151 views

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); 
}
Correct answer Thom Parker

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;

 

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
October 8, 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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
October 9, 2025

Perfect Thom,

Thank you very muh

------------------------------------------------------------------------[Sighs] - Trying my hardest to learn all this
Thom Parker
Community Expert
Community Expert
October 9, 2025

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

 

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