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

sushantmalsure
Mega Sage
Mega Sage

Can you describe more this business requirement ?

What is already there and what is expected outcome with screenshots?

 

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

In a catalog form , I have created two variables i.e- Lastname and check digit.

So when a user entered something in last name  field then automatically (starting character which user entered in last name) should appear in check digit field .

 

For example: 

Lastname -Hello (user entered hello)

Check digit -H( it should automatically get first character)

I do not know the exact scenario here but here is onChange() script you need to create on catalog item which runs on change of last_name variable:

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '' || newValue == oldValue) {
      return;
   }
   var valToSet = newValue.substring(0, 1);
   g_form.setValue('check_digit',''); // replace with correct variable name of check digit
   g_form.setValue('check_digit',valToSet); // replace with correct variable name of check digit


   //Type appropriate comment here, and begin script below
   
}

 

 

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

As you can see in the picture in 

PHname field I entered Hello, so automatically I need to get first character H in check digit field