capitalize first letter in text field

Avatar

Avatar

eugzl

Avatar

eugzl

eugzl

28-09-2016

Hi All.

I design form in LiveCycle and I would like capitalize first letter in Last Name text field. Could someone let me know how to capitalize it in JavaScript?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

mouslander

Avatar

mouslander

mouslander

30-09-2016

I think I finally got this to work. On the Exit event for the field I put:

this.rawValue = this.rawValue.toLowerCase().replace(/\b[a-z]/g, function replacer(match) { return  match.toUpperCase(); }); 

this forces the first letter of each word to UpperCase

Answers (4)

Answers (4)

Avatar

Avatar

mouslander

Avatar

mouslander

mouslander

30-09-2016

If you just want to force everything to upper case then just put this on the fields change event:

xfa.event.change=xfa.event.change.toUpperCase();

Avatar

Avatar

eugzl

Avatar

eugzl

eugzl

30-09-2016

Hi Bruce. Thanks for replay.

Is possible to capitalize all words in Last Name if it contains: space, hyphen, single quote or combination of letters and those characters? If yes. Can you show how to do it?

Thanks.

Avatar

Avatar

mouslander

Avatar

mouslander

mouslander

30-09-2016

Something is not correct. I get a return value of Empty

Avatar

Avatar

_Bruce_Robertson

MVP

Avatar

_Bruce_Robertson

MVP

_Bruce_Robertson
MVP

29-09-2016

Hi,

You could add the following JavaScript code in the exit event of your text field.

if (!this.isNull)

{

    this.rawValue = util.printx(">?<*",this.rawValue);

}

This changes the first character (represented by the ?) to uppercase (represented by the >) and all trailing characters (represented by the *) to lowercase (represented by the <). If you need to do the same hyphenated names or Van Der Valk's and the like you can try this JavaScript in the exit event;

function toTitleCase(textValue) {

    return
textValue.toLowerCase().replace(
/\b[a-z]/g, function replacer(match) { return
match.toUpperCase(); });

}  

if (!this.isNull)

{

  
this.rawValue
= toTitleCase(this.rawValue);

}

Regards

Bruce