0

Please have a look at my code. I'm trying to set the actor with the variables set near the top of my page. Name works fine but I can't get email to work. Can you tell me how to modify the code so that it recognizes the email variable? Right now it says 'mailto:email' and I know that is wrong and it does not work. Name does work, however, so I know that I am close. Thank you.

$("#myButton").click(function(){
    var name = $("#nameID").val();
    var email = $("#emailID").val();
    // Save the name in localStorage.
    localStorage.setItem('name', name);
    // Save the email in localStorage.
    localStorage.setItem('email', email);
    init();
    document.location.replace("page2.html");
});



function init() {

            var stmt = new ADL.XAPIStatement(
                new ADL.XAPIStatement.Agent('mailto:email', name),
                new ADL.XAPIStatement.Verb('http://adlnet.gov/expapi/verbs/completed', 'completed'),
                new ADL.XAPIStatement.Activity('act:http://johnmenken.blogspot.com/2016/01/practice-sending-xapi-statements.html', 'Diamond in the Rough',
                    'Article on curation by Ben Betts and Allison Anderson.')   
            );
            //generates a unique ID for the statement
            stmt.generateId();
            //Other contextual information about the Activity
            stmt.addOtherContextActivity( new ADL.XAPIStatement.Activity('Category:Curation') );
            //Registration: An instance of a learner experiencing a particular Activity.
            stmt.generateRegistration();

            ADL.XAPIWrapper.changeConfig({
                'endpoint': 'https://lrs.adlnet.gov/xapi/',
                'user': 'xapi-tools',
                'password': 'xapi-tools',
                'auth': 'xapi-tools'
            });

            ADL.XAPIWrapper.sendStatement(stmt);
}
John M.
  • 347
  • 1
  • 11

1 Answers1

0

This isn't really so much a Tin Can API question as a plain JavaScript question.

There are any number of ways to solve this, but based on what you currently have I would either construct the Agent object in the click handler and pass it to the init function or pass the values for "name" and "email" to the init function themselves. Name is a red herring, it isn't likely working the way you think it is, you just happen to be getting window.name a global accidentally, and more than likely it is the empty string.

init(email, name);

And then inside of init:

function init(actorEmail, actorName) {

        var stmt = new ADL.XAPIStatement(
            new ADL.XAPIStatement.Agent('mailto:' + actorEmail, actorName),

I switched to include "actor" in the variable name for differentiation, but there is no technical reason why you must.

Brian J. Miller
  • 2,169
  • 1
  • 12
  • 12