Skip to main content
Participating Frequently
June 14, 2019
Answered

count character and add text to location

  • June 14, 2019
  • 1 reply
  • 710 views

I am trying to count the number of numbers and add a + symbol to the second to last value in form field

example

user input into field 1000

form format 10+00

user input into field 10000

form format 100+00

user input into field 100000

form format 1000+00

This topic has been closed for replies.
Correct answer Thom Parker

Here's a simple general purpose script for this

event.value = event.value.replace(/(\d\d)$/,"+$1");

If you want to change the actual value of the field, this script should be placed in the validation or "WillCommit" event script.

If you just want to change how the field is displayed to the user, then it should be placed in the Format Script.

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
June 14, 2019

Here's a simple general purpose script for this

event.value = event.value.replace(/(\d\d)$/,"+$1");

If you want to change the actual value of the field, this script should be placed in the validation or "WillCommit" event script.

If you just want to change how the field is displayed to the user, then it should be placed in the Format Script.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often