Forum Discussion
TH-bf52b1b3-f6f
5 years agoCommunity Member
How to send quiz results via mail automatically via Javascript
Hi all,
until now I am able to let create a mail with the results of 5 quizzes automatically. But the learner could adapt that mail text and has to hit the "Send"-button in his mail client.
H...
JoshDean-9a3016
4 years agoCommunity Member
I tested the code above after I created a few variables (r1,r2, etc.) to match yours.
I would remind that JavaScript only runs when the project is published. You can also add a JavaScript alert to generated a popup to display a value to check how things are working. With this approach you can see the value of variables along the way. console.log can help with this too if you need many alerts.
alert("The value of results at this point is " + results.toString())
Your code worked well for me so I'd guess your variables aren't getting assigned from your quiz results in the earlier step.
I also updated your version a little using an Array.toString() function that easily lists a series of variables. Hopefully it's useful to someone.
var player = GetPlayer();
var status=player.GetVar("completion");
var email = 'recepientsmailaddress@here.com';
results = [
player.GetVar('r1'),
player.GetVar('r2'),
player.GetVar('r3'),
player.GetVar('r4'),
player.GetVar('r5')
];
alert("The value of results at this point is " + results.toString())
var subject = 'My quiz results of XYZ Quiz';
var emailBody = 'My quiz results:' + results.toString();
window.location.href='mailto:'+email+'?subject='+subject+'&body='+encodeURIComponent(emailBody);