Skip to main content
Known Participant
January 4, 2018
Answered

Check this script (Gilads' script)

  • January 4, 2018
  • 2 replies
  • 893 views

I'm using this script to show/hide a field on a timer, and it works fine, but now I'd like to have the field remain visible if populated (it's a drop down). Here's the script I'm using:

        if (util.printd("",new Date())=="") {

    this.getField("Text16").display=display.visible;

    var timeout = app.setTimeOut("this.getField(\"Text16\").display=display.hidden;", 15000);

} else this.getField("Text16").display=display.hidden;

I have this attached to a popMenu button. Is it possible to continue to use this script but to add a bit to cancel out the timer when Text16 is populated? It'll then go back to hidden when reset or when blank. Thanks guys

This topic has been closed for replies.
Correct answer Thom Parker

You can do this by making the timeout script a little more complicated.  Try this:

var timeout = app.setTimeOut("if(this.getField(\"Text16\").value == \"\") this.getField(\"Text16\").display=display.hidden;", 15000);

And as Try says, the first line code (the if) doesn't do anything, you can delete it.

2 replies

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
January 4, 2018

You can do this by making the timeout script a little more complicated.  Try this:

var timeout = app.setTimeOut("if(this.getField(\"Text16\").value == \"\") this.getField(\"Text16\").display=display.hidden;", 15000);

And as Try says, the first line code (the if) doesn't do anything, you can delete it.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
pdfUser1Author
Known Participant
January 4, 2018

Thom, thanks for trying to help. The code you provided kinda works but if I make a selection and reset the field the field stays visible. And also when (after) I make a selection and clear the field it still stays visible. It should go hidden.

Thom Parker
Community Expert
Community Expert
January 4, 2018

The script I provided does exactly what you asked.  Changing the visibility for other actions is a different issue. You've got a somewhat complicated process here.

You do an enormous amount of PDF scripting.  And have been for a very long time now. You really aught to have learned more about scripting than you have. I would suggest you do just that. Spend some time and actually learn about this. Or hire someone. You do enough of this that it would be worthwhile.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
January 4, 2018

The first line doesn't make sense. What are you trying to do there?

pdfUser1Author
Known Participant
January 4, 2018

I'm sorry, I didn't make it clear. When you originally helped me with this bit of script it was back when the AUF was open for q's and a's. I asked for help to show a field on hide a field on a specific date. Well, I still don't know javascript well enough, but I can play around with it well enough to, at times, to modify a working script. I deleted the date info and the script still worked so I left it in, but I didn't know what I was doing and why. So, the script works to show and hide the field.

But now, I would like to show the field and if I make a selection from the drop down it would stay visible. Keeping the timer command, of course, it would go hidden if the drop down field was blank or on Reset after the allotted time. I played around with a bit of show/hide coding but this time I can't figure it out.

I tried the script Thom provided and it worked (somewhat). The field stayed visible after I made a selection from the drop down. But, not on Reset or clear. It remained visible. I'd like the field to go hidden on reset or clear or blank like it does with the timer script.