Skip to main content
New Participant
August 13, 2020
Answered

Acrobat 9 Form JavaScript to clear a field only once

  • August 13, 2020
  • 2 replies
  • 1872 views

Useing Acrobat Pro 9, I have a few fields on a fillable form. On the text fields, the default text is "none". I'm trying to save my users some typing by clearing the text field when it is clicked on so they won't have to back space the word "none" out of the field before they enter something in it.  But only the first time because I don't want what they entered into the filed to be cleared if they want to go back in and add to it. Here's what I tried in Field -> Properties -> Actions -> Mouse Down - Run a JavaScript ...

 

var X = "none"
var Y = this.getField("Speaker").value;
if (X == Y);
this.getField("Speaker").value = "";
else
this.getField("Speaker").value = Y;

 

This is supposed to check to see if the field contains the default value "none". If it does, it sets the field to "". If The field does not contain the default value "none" ii is supposed to leave what is in there. What happens is that it always clears the field no matter what is in it! I would appreciate some help on this. I'm an ASP programmer, never used JavaScript, much less in a PDF.

 

(No combination of curly brackets seems to be acceptable to the script checker.)

 

Thank you!

Jerry

 

 

This topic has been closed for replies.
Correct answer Jerald5CBE

Thank you so much, this worked perfectly as well!

 

Jerry

2 replies

try67
Community Expert
August 13, 2020

Drop the semi-colon after the if-statement... You can also drop the else-clause, as it does nothing, basically.

Jerald5CBEAuthorCorrect answer
New Participant
August 13, 2020

Thank you so much, this worked perfectly as well!

 

Jerry

Nesa Nurani
Community Expert
August 13, 2020

Try this:

if(event.target.value == "none"){
event.target.value = "";
}

New Participant
August 13, 2020

Thank you very much! This worked perfectly.

 

Jerry