get Alert when max characters reached

New Here ,
Aug 22, 2018

Copy link to clipboard

Copied

I have set a character limit for a Textfield.

i try to show the remaining characters without success.

alternatively i try to show an error message when the limit is reached

var laenge = this.getField("Overline").value;

event.rc = true;

if (laenge > 10)

  {

     app.alert("Max. 40 characters incl. spaces");

     event.rc = false;

  }

else

{

    event.target.textColor = color.black;

}

Is there a way to display the remaining characters?

if not, what am I doing wrong with the code here?

Adobe Community Professional
Correct answer by gkaiseril | Adobe Community Professional

A more complex way of performing this task:

Countdown Maximum Length Input

The approach used by D.P. Story is to use the "AFMergeChange()" function to obtain the length of the form field being filled in dynamically.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

102

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

get Alert when max characters reached

New Here ,
Aug 22, 2018

Copy link to clipboard

Copied

I have set a character limit for a Textfield.

i try to show the remaining characters without success.

alternatively i try to show an error message when the limit is reached

var laenge = this.getField("Overline").value;

event.rc = true;

if (laenge > 10)

  {

     app.alert("Max. 40 characters incl. spaces");

     event.rc = false;

  }

else

{

    event.target.textColor = color.black;

}

Is there a way to display the remaining characters?

if not, what am I doing wrong with the code here?

Adobe Community Professional
Correct answer by gkaiseril | Adobe Community Professional

A more complex way of performing this task:

Countdown Maximum Length Input

The approach used by D.P. Story is to use the "AFMergeChange()" function to obtain the length of the form field being filled in dynamically.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

103

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 22, 2018 0
Adobe Community Professional ,
Aug 22, 2018

Copy link to clipboard

Copied

Try this:

var laenge = this.getField("Overline").value.length;

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 22, 2018 0
New Here ,
Aug 22, 2018

Copy link to clipboard

Copied

unfortunately did not work.

i also try var laenge = this.getField("Overline").value.toString().length; without success.

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 22, 2018 0
Adobe Community Professional ,
Aug 22, 2018

Copy link to clipboard

Copied

Use following lines:

console.show();

var laenge = event.value.length;

console.println("laenge: " + laenge);

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 22, 2018 0
Most Valuable Participant ,
Aug 22, 2018

Copy link to clipboard

Copied

Where did you place this code? Under what event?

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 22, 2018 0
Adobe Community Professional ,
Aug 22, 2018

Copy link to clipboard

Copied

A more complex way of performing this task:

Countdown Maximum Length Input

The approach used by D.P. Story is to use the "AFMergeChange()" function to obtain the length of the form field being filled in dynamically.

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 22, 2018 1