7 Replies Latest reply on Apr 30, 2010 10:14 AM by Kevin Cavallo

    Text Formatting

    GaryBarham

      This a two pronged question as shown below.

       

      1) How can I format a text field (such as a postal code) so that it will automaticall be formatted as all uppercase.

      2) How can I format Firstname Lastname so that the first letters are always capitalized. The same goes for an organisation name such as bank of toronto.

       

      Thanks for your suggestions.

        • 1. Re: Text Formatting
          Steve L Walker Level 5

          1) postal code

           

          // form1.page1.subform1.postalCode::exit - (JavaScript, client)


          var postalCode = this.rawValue;

          this.rawValue = postalCode.toUpperCase();

           

          2) capitalize first letters

           

          // form1.page1.subform1.bankName::exit - (JavaScript, client)


          var str = this.rawValue;

          var arrayOfStrs = str.split(" ");

          var newArrayOfStrs = new Array();


          for (var i=0; i < arrayOfStrs.length; i++) {

            var str = arrayOfStrs[i];

            var strLen = str.length;

            var firstLetter = str.substring(0,1);

            var theRest = str.substring(1,strLen);

            newArrayOfStrs[i] = firstLetter.toUpperCase() + theRest;

          }


          this.rawValue = newArrayOfStrs.join(" ");

           

          Steve

          • 2. Re: Text Formatting
            GaryBarham Level 1

            Steve, your help has been tremendous but I have one other minor query for you. When I input the name of the organization, such as bank of canada and tab to another field it is not capitalized the moment I exit from the organization name field. I have to click back in the organization field in some cases 3 times before the formatting is applied. How can the script be modified so that the moment I exit the field the formatting is applied automatically? I am experiencing the same problem with my postal code.

             

            Thanks.

            • 3. Re: Text Formatting
              Steve L Walker Level 5

              Are you referring to my form or a form you developed?

               

              I am not experiencing that behaviour in my form in Reader/Acrobat 9.2.

               

              Steve

              • 4. Re: Text Formatting
                GaryBarham Level 1

                form1.#subform[0].Table1.Row1.Organization_name::click - (JavaScript, client)

                var

                 

                 

                str = this.rawValue;

                var

                 

                 

                arrayOfStrs = str.split(" ");

                var

                 

                 

                newArrayOfStrs = new Array();

                for

                 

                 

                (var i=0; i < arrayOfStrs.length; i++) {

                 

                var str = arrayOfStrs[i];

                 

                var strLen = str.length;

                 

                var firstLetter = str.substring(0,1);

                 

                var theRest = str.substring(1,strLen);

                newArrayOfStrs[i]

                = firstLetter.toUpperCase() + theRest;

                }

                this.rawValue

                = newArrayOfStrs.join(" ");

                 

                 

                Hello Steve, I was not able to respond to your last post as I was terribly busy. The above is the script I am using to format my name field so that the first letter of the organisation's name is capitalized. What is happening (running acrobat reader 9.3 on one laptop and acrobat pro on another) is that even after I exit the field the name is not formatted. I have to click back in the field a few times for the format to take hold. It is unusual as I assumed that the text format would be applied immediately. This is indeed frustrating. Thanks for any advice you can offer.

                • 5. Re: Text Formatting
                  Kevin Cavallo Level 4

                  How about putting your script in the exit event rather than the click event.  The click will fire when you enter the field (assuming you click with the mouse), before the text is entered, then not fire until you click on the field again.  Exit will fire when you leave the field after entering the text.

                  • 6. Re: Text Formatting
                    GaryBarham Level 1

                    Kevin, your advice was right on target.

                    Thanks.

                    • 7. Re: Text Formatting
                      Kevin Cavallo Level 4

                      Looking back at the posts, Steve's example actually had it in the exit event but it's easy to overlook.  Glad it worked out for you.