Expand my Community achievements bar.

SOLVED

Text Formatting

Avatar

Level 2

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 Accepted Solution

Avatar

Correct answer by
Level 6

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.

View solution in original post

7 Replies

Avatar

Former Community Member

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

Avatar

Level 2

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.

Avatar

Former Community Member

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

Avatar

Level 2

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.

Avatar

Correct answer by
Level 6

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.

Avatar

Level 2

Kevin, your advice was right on target.

Thanks.

Avatar

Level 6

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.