Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Formatting name text to Last name uppercase and first name lower case

New Here ,
Apr 07, 2022 Apr 07, 2022

I have a form that has a single name field: "LAST NAME, First name" in the same field. I copy and paste the name in from other source but it comes in all different formatting, sometimes all lower case sometimes in all upper case. Is it possible to have a script that changes the formatting to last name all upper case e.g (SMITH) and first name normal e.g (John) with the comma in between as above? e.g  Name:  SMITH, John.

I have been looking for the right script to use for this for so long.   

TOPICS
Acrobat SDK and JavaScript
958
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 07, 2022 Apr 07, 2022

Try this code:

 

if (event.value) {
	var parts = event.value.split(", ");
	if (parts.length==2) {
		event.value = parts[0].toUpperCase() + ", " + parts[1].charAt(0).toUpperCase() + parts[1].substr(1).toLowerCase();
	}
}
Translate
Community Expert ,
Apr 07, 2022 Apr 07, 2022

Are you talking about changing the name of the field, or changing its value?

If the latter, are you talking about changing the actual value, or just how it is presented on the page (its formatting)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2022 Apr 07, 2022

Changing the value.  I copy the persons name from a different form into my form.  I need the field to auto format to upper case last name and lower case first name (with capital at the start of course).   It can be just the way it's presented that changes as long as it stays that way when it's printed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2022 Apr 07, 2022

Sorry, I mean i need the value to auto fomat

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2022 Apr 07, 2022

I found this in the properties 

Hall23939010crcs_0-1649325246126.pngexpand image

Just need the script to go in here

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2022 Apr 07, 2022

Try this code:

 

if (event.value) {
	var parts = event.value.split(", ");
	if (parts.length==2) {
		event.value = parts[0].toUpperCase() + ", " + parts[1].charAt(0).toUpperCase() + parts[1].substr(1).toLowerCase();
	}
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2022 Apr 07, 2022

That worked perfectly!!!!   your amazing 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2022 Apr 07, 2022

Hi,

It's correct only the first name is only composed with one name, else you must write something like that:

Note: I modified the previous script if you are using composed first names with hyphen.

 

var theName=event.value.split(",");
if (theName.length>1) {
	var firstName=theName[1].toLowerCase();
	for (var i=0; i<firstName.length-1; i++) {
		if (firstName[i]==" " || firstName[i]=="-") {
			firstName=firstName.substr(0,i+1)+firstName.substr(i+1,1).toUpperCase()+firstName.substr(i+2);
		}
	}
	event.value=theName[0].toUpperCase()+","+firstName;
} else event.value=event.value.toUpperCase();

 

@+

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2022 Apr 26, 2022
LATEST

Thank you 🙂   That is fantastic!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines