Concatenate First name & Last name variable

Kri
Tera Guru

I want to Concatenate First name & Last name variable value in Full name in the catalog item

 

I tried the below onchange client script for lastname


{
var fname=g_form.getValue('first_name');
var lname=g_form.getValue('last_name');
var ans = fname.concat(lname);
g_form.setValue('full_name', ans);

}

 

but I need space inbetween first name & last name currently it is combining the both variable values and also can you suggest which client script I need to prefer?

1 ACCEPTED SOLUTION

Priyanka0402
Mega Sage
Mega Sage

Hello @Kri , 

Did you try the above solution?

If my response helped please mark it correct and close the thread.

 

Thanks.

View solution in original post

3 REPLIES 3

Priyanka0402
Mega Sage
Mega Sage

Hello @Kri ,

You can modify your script as:

 var fname = g_form.getValue('first_name');

var lname = g_form.getValue('last_name');

var ans = fname + ' ' + lname;

g_form.setValue('full_name', ans);

 

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards

Priyanka

Kartik Choudha1
Tera Guru

Hi There,

 

You can try below code as well. 

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var fname= g_form.getDisplayValue('first_name');
var lname= g_form.getDisplayValue('last_name');

g_form.setDisplayValue('full_name', fname+ ' ' + lname);

}

 

Mark helpful/correct if the answer helps

 

Regards,

Kartik

Priyanka0402
Mega Sage
Mega Sage

Hello @Kri , 

Did you try the above solution?

If my response helped please mark it correct and close the thread.

 

Thanks.