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
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 👍👍
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
Жыл бұрын
Thanks! This solution works beautifully.
@nicholasmartinelli3
Жыл бұрын
AMAZING, thank you for the solution!
Hey, this was extremely helpful. thank you. couldn't find this solution anywhere else up until now. cheers.
This is super helpful!
thats very simple and easy to understand, thanks a lot!
Very useful. Thank you so much.
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!
How do I get the instructional text back if the filled-in text is taken out?
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
great
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
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.
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
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
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!
Excellent Tutorial but one question what if the user hits ESC will the text reappear by default?
@joseantonioespindolalarios3511
6 жыл бұрын
Add an action "on blur" with "if(event.target.value=="")event.target.value=event.target.defaultValue;"
@angiebareno7360
6 жыл бұрын
I tried this and it didn't work. Are we missing something in the script?
@Toolmancer
4 жыл бұрын
@@angiebareno7360 this is 2 years too late but it only works once you click out of the fillable fields.