Transform learner name to proper case
I'm trying to write some JavaScript that will convert the learner's first name to proper case. I was able to successfully get it to convert to all uppercase using the following code:
var player = GetPlayer();
var newVar = player.GetVar("LastName");
newVar = newVar.toUpperCase();
player.SetVar("LastName", newVar);
But when I switched the trigger to a submit button, this no longer works. It used to trigger when the Textbox loses focus. I'm not sure why it doesn't work now that the trigger is different.
Here is the code I have which I think should convert it to proper case, but I'm not sure if the problem is the code or the submit button trigger.
var player = GetPlayer();
var myName = player.GetVar("FirstName");
var array = myName.split(',');
var str = array[1];
var newName = str.slice(0,1).toUpperCase() + str.slice(1);
player.SetVar("FirstName", newName);
Any help appreciated!