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

Turn "OCT" into "10" in text boxes

Explorer ,
Oct 28, 2025 Oct 28, 2025

"NOTMONTH" = OCT

"NM" = *where 10 is supposed to be*

 

This is the script that I have in the calculation field of NM:

var NOTMONTH = this.getField("NOTMONTH").valueAsString;
if (NOTMONTH=="JAN") event.value = "01";
else if (NOTMONTH=="FEB") event.value = "02";
else if (NOTMONTH=="MAR") event.value = "03";
else if (NOTMONTH=="APR") event.value = "04";
else if (NOTMONTH=="MAY") event.value = "05";
else if (NOTMONTH=="JUN") event.value = "06";
else if (NOTMONTH=="JUL") event.value = "07";
else if (NOTMONTH=="AUG") event.value = "08";
else if (NOTMONTH=="SEP") event.value = "09";
else if (NOTMONTH=="OCT") event.value = "10";
else if (NOTMONTH=="NOV") event.value = "11";
else if (NOTMONTH=="DEC") event.value = "12";

 

NM used to say "OCT" but now it doesn't popluate anything, so I'm not sure what I did.

TOPICS
Create PDFs , Edit and convert PDFs , JavaScript , PDF , PDF forms
85
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 ,
Oct 28, 2025 Oct 28, 2025

The script seems to be good, so now you need to do some debug.  

First, look in the console window (Ctrl-j) to see if there are any reported errors. 

If there are no errors, then add some debug code to your script.  Add this line immediately after the first line. 

 

console.println("NotMonth=" + NOTMONTH);

 

This will print the value acquired from the "NOTMONTH" field to the console window.   

 

 

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

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 ,
Oct 28, 2025 Oct 28, 2025

Use this to better see the full value:

console.println("NotMonth=" + NOTMONTH.toSource());

For example, if there's a space after "OCT" it will be hard to spot with the code above.

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 ,
Oct 28, 2025 Oct 28, 2025
LATEST

Try this script and see if it works for you:

var val = this.getField("NOTMONTH").valueAsString.toUpperCase().trim();
var monthMap = {
  JAN:"01", FEB:"02", MAR:"03", APR:"04", MAY:"05", JUN:"06",
  JUL:"07", AUG:"08", SEP:"09", OCT:"10", NOV:"11", DEC:"12"
};

event.value = monthMap[val] || "";
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