Skip to main content
Participating Frequently
October 16, 2024
Answered

Auto-capitalize fields when opening PDF

  • October 16, 2024
  • 1 reply
  • 1474 views

We just converted to a digital version of our sales sheets for my company via PDF. I have each field vaildate with the "event.value = event.value.toString().toUpperCase() ;" script, which would be fine except the sales people are using Chromebooks where that function doesn't work, or really any JS. Basically they fill out the forms, save to a cloud, where we in the office can open them on our PCs.

 

The sales people we have are notorius for using lower-case for everything, proper names, etc. So our solution was to just have all caps on the forms. Problem is that Chromebooks do not have a caps lock, so we had to program the PDFs to do it. Unfortuately, as I mentioned, the books do not work with the validate function.

 

When we open them on our PCs with the lowercase fields, the fields will validate and the script will work to make the fields uppercase again, but ONLY if we modify the field. If we don't make changes, even tabbing across, nothing will validate and change.

 

Is there a simple way to make each field automatically change to uppercase when the documents are opened on our PCs if they were entered in as lowercase with the Chromebooks?

 

I was thinking a document-level script but I am not too sure how to go about it.

 

tl;dr

Need a script to automatically make certain field's values uppercase when opening the PDF.

 

Thank you! I hope what I am asking makes sense. I am new to JS with PDFs.

This topic has been closed for replies.
Correct answer Nesa Nurani

@Nesa Nurani is a very knowlegable expert who has taught with a lot with her answers on this forum.  She probably has a reason to include it that I hadn't thought of.


You should include it because if any of the fields is not a string, the script will stop there, and it won't work on fields after that field (for example if the field is a number).

1 reply

PDF Automation Station
Community Expert
Community Expert
October 16, 2024

Yes, a document level script will work:

 

for(var i=0; i<this.numFields; i++)

{

var fieldName=this.getNthFieldName(i);

var oFld=this.getField(fieldName);

if(oFld.type=="text")

{oFld.value=oFld.value.toString().toUpperCase() ;}

}

Nesa Nurani
Community Expert
Community Expert
October 16, 2024

Add:  toString()

PDF Automation Station
Community Expert
Community Expert
October 16, 2024

You can add that but it doesn't matter.  Letter/number combos will be interpreted by the JavaScript engine as a string.  Numbers might not, but there's nothing to convert to upper case, in that case.