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

Substring not a function

New Here ,
Dec 28, 2017 Dec 28, 2017

Copy link to clipboard

Copied

I'm running Acrobat Pro DC. I have a text field ("CC.CardNumber") with an Action/OnBlur event that runs the following script that produces this error. I've researched this for hours and can't see where my code is incorrect.

var fld = this.getField("CC.CardNumber");

var first = fld.value.substring(0,1);

fld.value = first;

TypeError: fld.value.substring is not a function

3:AcroForm:CC.CardNumber:Annot1:OnBlur:Action1Exception in line 1051 of function AFSimple_Calculate, script byteCodeTool

TOPICS
Acrobat SDK and JavaScript , Windows

Views

2.1K

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
community guidelines

correct answers 1 Correct answer

LEGEND , Dec 28, 2017 Dec 28, 2017

JavaScript has the habit of converting character representations of number strings to IEEE floating point numbers and as such many string functions or methods do not work. You have to force the numeric value to a string format using the String() constrictor.

Try:

var fld = this.getField("CC.CardNumber");

var first = String(fld.value).substring(0,1);

fld.value = first;

The other approach would be to use the RegExp object to split the CC.CardNumber.

Votes

Translate

Translate
LEGEND ,
Dec 28, 2017 Dec 28, 2017

Copy link to clipboard

Copied

JavaScript has the habit of converting character representations of number strings to IEEE floating point numbers and as such many string functions or methods do not work. You have to force the numeric value to a string format using the String() constrictor.

Try:

var fld = this.getField("CC.CardNumber");

var first = String(fld.value).substring(0,1);

fld.value = first;

The other approach would be to use the RegExp object to split the CC.CardNumber.

Votes

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
community guidelines
New Here ,
Dec 28, 2017 Dec 28, 2017

Copy link to clipboard

Copied

LATEST

Worked! Thanks much.

Votes

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
community guidelines