Forum Discussion
Using Text Entry Fields and Javascript
Hello e-learning peeps, do you ever have what you think is a great creative idea, but lack the skill (and have limited time to develop the skill needed) to implement it in Storyline? Sadly this is where I am at right now ;)
My idea was to have a user enter their name in a text entry field and then display their name on a slide with a salutation like Hello there... using variable reference to display said name, so far pretty easy.
Next I want to have another text entry field convert the name entered into the hexadecimal equivalent using ASCII to hex conversion so I thought hey lets try Javascript, which I freely confess I know next to nothing about so because of limited time, and lack of skill I of course "borrowed" some code that I think may work, if only I knew what I was doing :(
Anyhoo here is the slide in question, I am sure that my issue is more or less:
A.) Comically simple to those with more smarts and skill than me
or
B.) Like Icarus I reached for the sun and got burnt falling from the heavens in a fiery heap.
Thanks for any help you can offer or even a gentle scolding would suffice :)
- RichardWatsonSuper Hero
Michael,
Try this. I'm still learning JavaScript, but it works for your specific situation..
Richard
var player = GetPlayer();
var learnerName = player.GetVar("FirstName_LastName");// Calculate the hex value
var hexText = convertToHex(learnerName);// Set the 'HexDisplay' variable in Storyline with the hexText
player.SetVar("HexDisplay", hexText);function convertToHex(input) {
var hexString = '';
for (var i = 0; i < input.length; i++) {
var charCode = input.charCodeAt(i);
var hexValue = charCode.toString(16);
hexString += hexValue + ' ';
}
return hexString.toUpperCase(); // Convert the hexString to uppercase (optional)
} - MichaelHebertCommunity Member
Wow Richard thanks so much this is great. I really appreciate it
- RichardWatsonSuper Hero
Michael,
There are many other JavaScript experts on this site. As I am still learning, there may be a better way to do this. That being said, I did test this and it appeared to work as expected. It's all part of my JavaScript learning adventure. Walt are you out there? I know this is an area you work in more than I. Perhaps you can chime in and provide your thoughts on the code?
Richard
- MichaelHebertCommunity Member
Thanks again Richard, I don't use JavaScript often and I think my main issues were getting Storyline 360 variables talking to talking to Javascript, setting up the var player variables properly, etc. just even seeing the minor corrections you made has helped me understand where I went wrong so thank you again.
- RichardWatsonSuper Hero
You are welcome. As I stated earlier, I'm still learning it myself. Good luck to you.
Richard