Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Acrobat 9 Form JavaScript to clear a field only once

Community Beginner ,
Aug 13, 2020 Aug 13, 2020

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

 

 

TOPICS
PDF forms
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Aug 13, 2020 Aug 13, 2020

Try this:

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

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 13, 2020 Aug 13, 2020
LATEST

Thank you so much, this worked perfectly as well!

 

Jerry

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 13, 2020 Aug 13, 2020

Try this:

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 13, 2020 Aug 13, 2020

Thank you very much! This worked perfectly.

 

Jerry

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 13, 2020 Aug 13, 2020

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 13, 2020 Aug 13, 2020
LATEST

Thank you so much, this worked perfectly as well!

 

Jerry

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines