How to get first character in a name.

User267
Tera Contributor

This are two fields in catalogue form.

PH last name- Mary

Check digit- when you entered something in field"PH last name" then the starting ( First character) letter of name will.

1 ACCEPTED SOLUTION

Riya Verma
Kilo Sage
Kilo Sage

Hi @User267 ,

 

 

Hope you are doing great.

 

Create on change client script on last name field and try usig below script in onchange function:

 

  var lastnameField = g_form.getValue('lastname');
  if (lastnameField.length > 0) {
    var firstCharacter = newValue.charAt(0);
    g_form.setValue('check_digit', firstCharacter);
  } else {
    g_form.clearValue('check_digit');
  }

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

View solution in original post

11 REPLIES 11

have you tried above onChange() script to be created on catalog item?

Have you replaced the variables with correct variable name?

I hope both these fields are string?

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

In check digit I need to get first character from PHname. So in your code there is no pH name right? How it will be working

I am using that under newValue as the client script is written on change of PH last name.

my code works perfectly and tested on my PDI.

i think you are not getting what is explained above .

 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Riya Verma
Kilo Sage
Kilo Sage

Hi @User267 ,

 

 

Hope you are doing great.

 

Create on change client script on last name field and try usig below script in onchange function:

 

  var lastnameField = g_form.getValue('lastname');
  if (lastnameField.length > 0) {
    var firstCharacter = newValue.charAt(0);
    g_form.setValue('check_digit', firstCharacter);
  } else {
    g_form.clearValue('check_digit');
  }

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

yeah I tried this, but it's not working