Skip to main content
Participating Frequently
October 2, 2018
Answered

How to create a SHOW button to show fields only if Adobe Reader is being used?

  • October 2, 2018
  • 1 reply
  • 6073 views

Hello,  I'm a newbie to Adobe pdfs and I have no experience with javascript.  I've created a fillable form with required fields.  I would like a button to be place at the top of the form which the user must click on before beginning the form.  Let's call this button the Show button.  The required fields of the form should not be visible unless the user is using Adobe Reader and not Acrobat.  When they click on the Show button, if they are using Reader, the fields will become visible for filling out and they may proceed.  If they are not using Reader, the fields will not be visible. Perhaps another button may be created that shows either Valid or Not Valid, with the color green for valid and red for not valid, and when clicking on the Show button, if they are using Reader, the button shows Green for Valid and they can proceed but if they are not using Reader then a red Not Valid.  Can this be done and if so, please explain. Thank you.

This topic has been closed for replies.
Correct answer try67

Try67,  it worked!!    However, I noticed that certain fields appear when they shouldn't.  One example is this: Radio Buttons for Gender selection, there are 3, Male, Female and a third one labeled nothing which is required when inserting radio buttons, there has to be 3.  It's marked as hidden yet when I opened the pdf after installing the code for load, all of the fields that are marked for hidden show even though they shouldn't. Can I prevent those fields from being visible?


You can create an array of fields names to ignore and then compare each field name against it.

However, there's absolutely no need to have 3 fields in a radio-button group. It will work just fine with just two...

1 reply

try67
Community Expert
October 2, 2018

This is all possible, but you're asking for quite a lot.

Let's focus on the first part.

To show fields if the file is opened in Reader you can use this code:

var fieldsToShow = ["Field1", "Field2", "Field3"]; // etc.

for (var i in fieldsToShow) {

    var f = this.getField(fieldsToShow);

    if (f) f.display = (app.viewerType=="Reader") ? display.visible : display.hidden;

}

Participating Frequently
October 3, 2018

Ok, I placed the code in Button properties, Actions:Mouse up, Execute a menu item, then under Actions: Mouse Up, Run a JavaScript=

  1. var fieldsToShow = ["Field1", "Field2", "Field3"]; // etc. 
  2. for (var i in fieldsToShow) { 
  3.     var f = this.getField(fieldsToShow); 
  4.     if (f) f.display = (app.viewerType=="Reader") ? display.visible : display.hidden; 
  5. }
try67
Community Expert
October 4, 2018

Also, to reply to your question: What's the point of having this button at all?

I'm starting to think that you may have a point.  I should just have all the fields visible to be filled out.  If there are any problems with completing the forms, I can always kick it back to the respondent and have them try again.  Maybe , that's the way to go with this.


- No, you shouldn't just delete it. It's obviously being used somewhere (or else the error message wouldn't appear at all). You can try to debug it to find out what goes wrong. The error message actually provides a lot of information that can help with that, such as the type of error, the name of the variable involved and the line in which it took place.

- I'm not saying you should get rid of the code to show/hide the fields entirely, just don't have it execute when a button is clicked.
Instead, you can execute it automatically when the file is opened, by moving it to a different location.