These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Looking for Caps script

cramia
Registered: Oct 6 2008
Posts: 33
Answered

Hello all!

I am looking for a script that changes lower case to upper case but ONLY the FIRST letter.

For example: If you type george clooney the script will change it to George Clooney.

I am not sure if it is possible with TWO different words (first and last name) on the SAME field.

The one that I am currently using changes the WHOLE text and that's not good for me.

Thanks!

CRamia

CRamia
New York

My Product Information:
Acrobat Pro 8.0, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Do you want a script called like title cas that will process multiple words?
Do you need to exclude connective words and articles?
Do you need hyphenated words processed?

function FirstWordTitleCase(sWord) {
// force first letter of word to upper case and all others lower case
return sWord.substr(0, 1).toUpperCase() + sWord.substr(1).toLowerCase();
}function SimpleTitleCase(sInput) {
var aInput = sInput.split(" "); // make an array split at space
// for each element of word array, capitalize the first letter
for(i = 0; i

George Kaiser

cramia
Registered: Oct 6 2008
Posts: 33
[quote=gkaiseril]Do you want a script called like title cas that will process multiple words?
Do you need to exclude connective words and articles?
Do you need hyphenated words processed?

function FirstWordTitleCase(sWord) {
// force first letter of word to upper case and all others lower case
return sWord.substr(0, 1).toUpperCase() + sWord.substr(1).toLowerCase();
}

function SimpleTitleCase(sInput) {
var aInput = sInput.split(" "); // make an array split at space
// for each element of word array, capitalize the first letter
for(i = 0; i

CRamia
New York

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Can you be more specific.

Where did you place this code?
Did you get any error messages on Acrobat's JavaScript debugging console?
What code did you use to call the functions?

Placing the code and executing it in the JavaScript debugging console resluted with when properly calling the function:

function FirstWordTitleCase(sWord) {// force first letter of word to upper case and all others lower casereturn sWord.substr(0, 1).toUpperCase() + sWord.substr(1).toLowerCase();} function SimpleTitleCase(sInput) {var aInput = sInput.split(" "); // make an array split at space// for each element of word array, capitalize the first letterfor(i = 0; i <aInput.length; i++) {aInput[i] = FirstWordTitleCase(aInput[i].toString() )} // end loopvar sNewString ='';// rebuild input string with modified wordsfor(i = 0; i <aInput.length; i++){sNewString += aInput[i] + ' ';} // end loopreturn sNewString.substr(0, sNewString.length -  1);}  // using the above defined functions:var InputString = 'this IS a TesT'; // text stringconsole.println("Input string: " + InputString); // display input stringvar TitleString = SimpleTitleCase(InputString); // process the input stringconsole.println("Result: " +TitleString); // display result Input string: this IS a TesTResult: This Is A Test undefined

George Kaiser

cramia
Registered: Oct 6 2008
Posts: 33
Mr. Kaiser,

I know that the script works...the problem is that I don't know were to put it in my PDF.

Thanks for your help and your time!


CRamia

CRamia
New York

Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi cramia,

This article at JavaScript Corner discusses the places where scripts can be used on text fields-

http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/scripts_form_fields/

Hope this helps,

Dimitri
www.pdfscripting.com
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
I would put the functions as a document level script so that any form field could use that code and then depending upon when I wanted the input field text to change either as a custom key stroke script to change the entry by each keystroke or as a validation script to change the field upon completion.

You can use the following script to force certain words. "sSpecialWords", to lower case except if the first word:

function TitleCase(sInput) {// lsit of special words not to title case in a position other than first wordvar sSpecialWords = 'a ' + 'an ' + 'and ' + 'as ' + 'at ' + 'but ' + 'by ' + 'em ' + 'for ' + 'if ' + 'in ' + 'is ' + 'of ' + 'on ' + 'or ' + 'the ' + 'this ' + 'to ' + 'v ' + 'via ' + 'vs ' + 'vs. ' + 'with  '; var aInput = sInput.split(' '); // make an array split at space// var sCharacter = '';// var sWord=''; // for each element of word array, capitalize the first letterfor(i = 0; i <aInput.length; i++) {if(i == 0) // first wordaInput[i] = aInput[i].substr(0, 1).toUpperCase() + aInput[i].substr(1).toLowerCase();else // check not first word for special wordsif (sSpecialWords.indexOf(aInput[i].toLowerCase(), 0) >= 0) aInput[i] = aInput[i].toLowerCase();else aInput[i] = aInput[i].substr(0, 1).toUpperCase() + aInput[i].substr(1).toLowerCase(); // title case word } // end loop for input string // rebuild input string with modified words with spacesreturn aInput.join(' ');}

George Kaiser

cramia
Registered: Oct 6 2008
Posts: 33
Dimitri wrote:
Hi cramia,This article at JavaScript Corner discusses the places where scripts can be used on text fields-

http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/scripts_form_fields/

Hope this helps,

Dimitri
www.pdfscripting.com
Thank you!!

CRamia
New York

cramia
Registered: Oct 6 2008
Posts: 33
I finally got the script to work...it is perfect...

Thanks a million!!


CRamia

CRamia
New York

geophray
Registered: Jun 13 2008
Posts: 40
How do you call on the document functions from the individual fields (either in the validation or custom keystroke scripts? I am kind of new at this... I used the functions outlined in the accepted answer and then tried this in both the validation and keystroke scripts. It works the first time, but then the text I type in the first time always pops back in even if I try to delete it or type something else...

event.value = SimpleTitleCase(this.getField("Processor").value);
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
A function is called by using its name as defined by the 'function' statement and providing the expected parameters within the parenthesis. To call the function I have provided:
TitleCase('string input');
And the called function will return a string. Exactly where and how this is used depends upon what one wants to do. It can be used by other functions, in a calculation, in a custom format action, and son on.

If you want to use this within a given field for the 'Custom format script' you need to access the correct object. It is usually best to use the 'event' when referencing the currently focused field. So would use the 'custom format script' of:
event.value = TitleCase(event.value);
Of course this assumes you do not have some other action or field trying to manipulate this field's value. Also if one tries to access this field's value the value will be the inputted value and not the formatted value.

George Kaiser

geophray
Registered: Jun 13 2008
Posts: 40
Thank you... that was just what I needed. :)
rshack
Registered: Nov 21 2009
Posts: 5
gkaiseril... I'm using your $.rawValue=$.rawValue.toUpperCase();, and love it for forcing uppercase in State fields.

I now want to use Title case; tried just changing the above syntax from "UpperCase" to LowerCase", but it failed I'm not a programmer at all, looking for something as easy as you provided for upper case changes.

rshackelford [at] 12vi [dot] org
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
The function was written for forms created with Acrobat and not Live Cycle Designer. Acrobat created forms do not use the 'revalue' property and Live Cycle Designer does not install document level functions in the same manner as Acrobat.

George Kaiser

Navyopie
Registered: May 18 2010
Posts: 11
Gkaiseril,
How would i modify the script so that the sSpecialWords could be the first word and not be title case?, im a rookie at this so please dont beat me up too much.
jjoseph
Registered: Mar 29 2011
Posts: 2
I have several fields in my form. I need to make them all uppercase. I have the script to do that for each form field. Is there a way to propagate the script to all the form fields? Can I do something at the document leve script to do this. By the way I am somewhat of a beginner.

Joe Joseph

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
If you created the form in Acrobat and not LiveCycle Designer, then any of the following methods should work.

You can enter the the following script into the custom validation script of all the fields:

event.value = event.value.toUpperCase();

If all of the fields are text fields, then you could place the code intro the custom format script.

If you use the "Edit Form in Acrobat" right click on the first field and select the "Properties" option, select the "Validation' tab, select the "Custom Validation Script" and enter the code. Copy the code. Click "OK" but do not close the pop up. Select the next field and select the "Custom Validation Script", paste the code, click "OK", and repeat for the next field until done.

George Kaiser

jjoseph
Registered: Mar 29 2011
Posts: 2
George,

Thank you... that was just what I needed. :)

Joe Joseph