Skip to main content
Inspiring
October 28, 2025
Question

Turn "OCT" into "10" in text boxes

  • October 28, 2025
  • 2 replies
  • 111 views

"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.

2 replies

Nesa Nurani
Community Expert
Community Expert
October 29, 2025

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] || "";
Thom Parker
Community Expert
Community Expert
October 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 PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
October 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.