Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Using .split to get First Name out of Full Name text field

Avatar

Level 2

I am trying to get the first name of an employee out of an Full Employee Name text field on my form (called EmpName) but I keep getting nothing.  I put the javascript code in the EmpName change event as follows:

 

Form0930.Page1.EmpName::change - (JavaScript, client)

 

var nameArray = this.rawValue.split(" ");

Page3.Congratulations.rawValue = "Congratulations " + nameArray[0] + "!";

I would put in test data in the Full Name field but only 'Congratulations ! '  displays in my text box.

Thanks,

1 Accepted Solution

Avatar

Correct answer by
Level 3
Level 3

Hi,

Your java script code seems correct. Write this code on the Exit event of 'Form0930.Page1.EmpName'.

Thanks

View solution in original post

3 Replies

Avatar

Level 10

Hi,

there are several ways to get the first name.

You can for example use a regular expression to find the first word in a string.

The just needs one line of code.

Put this script into the chage event of your field.

Hope this helps.

Avatar

Correct answer by
Level 3
Level 3

Hi,

Your java script code seems correct. Write this code on the Exit event of 'Form0930.Page1.EmpName'.

Thanks

Avatar

Level 2

That worked!  Thank you so much!  I thought I was losing my mind when my code didn't work.