Expand my Community achievements bar.

How to capitalize first letter in text field

Avatar

Former Community Member
Hi,



Could someone let me know how to capitalize the first letter in a text field? For example, if I was having users enter a first name, I would want to capitalize the first but not subsequent letters. I appreciate any help you can give. Thanks.



Jeff
8 Replies

Avatar

Level 7
Unfortunately MS VBA does not work within an Acrobat or LiveCycle Designer form, only JavaScript or FormCalc.



JavaScript has the "toUpperCase()" method and FormCalc has the "Upper()" function. You can use the sub string capabilities within JavaScript or FormCalc to split the string, capitalize the first letter, and recombine the pieces.

Avatar

Former Community Member
Hi Jeff



In the script window ,on the exit script event and formcalc as language put this script :



TextField1 = Concat(Left(upper(TextField1),1),Right(TextField1,Len(TextField1)-1))



Where in place of TextField you put the field name you gave in your form.



Regards Mike

Avatar

Former Community Member
Hi



Thanks Mike - I was looking for help with this as well.



I took your solution and changed it a bit so if they enter in upper or lower case or a mixture it goes to sentence case



Surname = Concat(upper(Left(Surname,1)),lower(Right(Surname,Len(Surname)-1)))



Change Surname to your field name



Dave

The old fogey (new to livecycle)

Avatar

Former Community Member
Hi Dave,



I did'nt test it but looks good. This give you, whatever the way people type in, the first letter in upper case and the rest in lower case.



Regards Mike

Avatar

Former Community Member
Could this script be adapted to capitalise the first letters of all of the words in a textfield?

Avatar

Level 7
For the code that reads:



Surname = Concat(upper(Left(Surname,1)),lower(Right(Surname,Len(Surname)-1)))



The correct case for the function name needs to used:



Surname = Concat(Upper(Left(Surname,1)), Lower(Right(Surname,Len(Surname)-1)))



One could use the "At()" function to find word boundaries in the string then process each word.



Or use JavaScript to be able to use the ability to split a string into an array and join the array elements into a string.

Avatar

Level 1

I was wondering if you can show me how to complete the script with "At()" function.I struggled a lot trying to implement javascript to capitalize the first letter of each word in a text box but apperantly I'm missing something. I appreciate your respond!


<SCRIPT LANGUAGE="JAVASCRIPT">
<!--

function capitalizeMe(obj) {
         val = obj.value;
         newVal = '';
         val = val.split(' ');
         for(var c=0; c < val.length; c++) {
                 newVal += val[c].substring(0,1).toUpperCase() +
val[c].substring(1,val[c].length) + ' ';
         }
         obj.value = newVal;
}

// -->
</SCRIPT>