Forum Discussion
AndrewRost
13 years agoCommunity Member
Retrieve LMS User Name as Variable
I know you can have a user fill in a text box with their name and then later use that variable for personalization. What we would like to do is programmatically retrieve the user name from the LMS....
SteveFlowers
11 years agoCommunity Member
Yep. This should work. Looks for the last space. If the last space is the next to last character, strip it off. Otherwise, keep it.
var LMSName="flowers, steve t";
if(LMSName.lastIndexOf(" ")==LMSName.length-2){
//has an initial
LMSName=LMSName.substring(0,LMSName.length-2).split(",");
nameOut=LMSName[1]+" "+LMSName[0];
}else{
//no initial
LMSName=LMSName.split(",");
nameOut=LMSName[1]+" "+LMSName[0];
}
document.write(nameOut);