PDFs: Use JavaScript to Clear Default Text

In this video, Neil Malek demonstrates how to use a little JavaScript code in Acrobat Pro to create default 'helper text' in a form, then clear the helper text out when you click in the text box.
The code used in this video is:
if(event.target.value==event.target.defaultValue) event.target.value="";
(if the current value of the text box is still set to its default value when you click, set the value to blank)

Пікірлер: 21

  • @roozbehebadi6661
    @roozbehebadi66612 жыл бұрын

    This is awesome! I also added two other scripts for On Blur and Mouse Exit actions: if(event.target.value=="")event.target.value=event.target.defaultValue ; This is vise-versa of what is in the On Focus, It would fills the field with default text if it left empty. Thanks man 👍👍

  • @jamiekingmedia
    @jamiekingmedia2 жыл бұрын

    Thanks Neil for this, and thanks @Roozbeh for your added contribution. Finding such a simple script easily and readily online is often half the battle. Here's the combination of scripts I used as per Neils and Roozbeh input: Field ACTIONS (in properties) On Focus: if(event.target.value==event.target.defaultValue) event.target.value=""; On Blur: if(event.target.value=="")event.target.value=event.target.defaultValue ; Mouse Exit: if(event.target.value=="")event.target.value=event.target.defaultValue ;

  • @KidAMRadio

    @KidAMRadio

    Жыл бұрын

    Thanks! This solution works beautifully.

  • @nicholasmartinelli3

    @nicholasmartinelli3

    Жыл бұрын

    AMAZING, thank you for the solution!

  • @squarebobspongepants1133
    @squarebobspongepants11334 жыл бұрын

    Hey, this was extremely helpful. thank you. couldn't find this solution anywhere else up until now. cheers.

  • @VivianUang
    @VivianUang8 ай бұрын

    This is super helpful!

  • @larrysew1939
    @larrysew19394 жыл бұрын

    thats very simple and easy to understand, thanks a lot!

  • @angiebareno7360
    @angiebareno73606 жыл бұрын

    Very useful. Thank you so much.

  • @hazellai8058
    @hazellai80587 жыл бұрын

    Hi, thanks for the sharing of this tips- it's very useful! Is there a way that we could limit the number of words in pdf's text fields using the if function? Appreciate your help!

  • @surfdoc11
    @surfdoc1111 ай бұрын

    How do I get the instructional text back if the filled-in text is taken out?

  • @thomaspeter8335
    @thomaspeter833510 жыл бұрын

    Dear Neil, Thanks for your reply. I had created a fillable form with a dropdown box named (company) with 5 company names. When I choose one of the company name I wish to display the form number at the bottom of page otherwise display blank field name (docnumber). Also please let me know which field properties I should insert the javascript. Thank you very much Thomas

  • @cricketbio3
    @cricketbio35 жыл бұрын

    great

  • @duckdodgers2843
    @duckdodgers28434 жыл бұрын

    This was very helpful thank you! How would I adjust the code so if the field is left blank it gets refilled with the default value? I tried using an if / else statement but I can't get it working.

  • @PDFAutomationStation

    @PDFAutomationStation

    4 жыл бұрын

    I would use a custom format script instead of an onFocus action script. if(!event.value){event.value="Whatever you want the field to say";} If the field is empty is will say whatever you want it to say. If it's empty it will say whatever the user keys in.

  • @dontbeafraid5313
    @dontbeafraid53135 жыл бұрын

    Hi. This is another great tutorial. I need some help in project where I have a radio button (yes or no) and what I am trying to accomplish is when the radio button is on yes, The showMe field shows up. i tried This code but didn't work If (event.target.value =="yes") { this.getField("showMe").display = display.visible; } else { this.getField("showMe").display = display. hidden; Hope you can help me. Thanks

  • @thomaspeter8335
    @thomaspeter833510 жыл бұрын

    if target value is equal to default value how to display a text box at the bottom of page to say Correct. Appreciate you reponse please.

  • @neilmalek

    @neilmalek

    10 жыл бұрын

    The answers to what you're looking for come from this page: stackoverflow.com/questions/8056046/copy-field-values-in-acrobat-using-javascript So, you wouldn't compare the target value against the default value, because the default value shows up on the screen. That would mean your user was simply typing the same message or value they saw in the box. Instead, you could say if (getfield("field1").value == getfield("field2").value) or if (getfield("field1").value == "desired value"), and if it was true, then you could set another field by typing getfield("field3").value = getfield("field1").valueAsString --> notice the difference between two == (is this equal?) and one = (set the first equal to the second). Good luck!

  • @0722fear
    @0722fear7 жыл бұрын

    Excellent Tutorial but one question what if the user hits ESC will the text reappear by default?

  • @joseantonioespindolalarios3511

    @joseantonioespindolalarios3511

    6 жыл бұрын

    Add an action "on blur" with "if(event.target.value=="")event.target.value=event.target.defaultValue;"

  • @angiebareno7360

    @angiebareno7360

    6 жыл бұрын

    I tried this and it didn't work. Are we missing something in the script?

  • @Toolmancer

    @Toolmancer

    4 жыл бұрын

    @@angiebareno7360 this is 2 years too late but it only works once you click out of the fillable fields.