Highlighted

Acrobat 9 Form JavaScript to clear a field only once

Community Beginner ,
Aug 13, 2020

Copy link to clipboard

Copied

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

 

 

Correct answer by Jerald5CBE | Community Beginner

Thank you so much, this worked perfectly as well!

 

Jerry

TOPICS
PDF forms

Views

69

Likes

Translate

Translate

Report

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

Acrobat 9 Form JavaScript to clear a field only once

Community Beginner ,
Aug 13, 2020

Copy link to clipboard

Copied

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

 

 

Correct answer by Jerald5CBE | Community Beginner

Thank you so much, this worked perfectly as well!

 

Jerry

TOPICS
PDF forms

Views

70

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 13, 2020 0
Engaged ,
Aug 13, 2020

Copy link to clipboard

Copied

Try this:

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 13, 2020 0
Community Beginner ,
Aug 13, 2020

Copy link to clipboard

Copied

Thank you very much! This worked perfectly.

 

Jerry

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 13, 2020 0
Most Valuable Participant ,
Aug 13, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 13, 2020 0
Community Beginner ,
Aug 13, 2020

Copy link to clipboard

Copied

Thank you so much, this worked perfectly as well!

 

Jerry

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 13, 2020 0