Forum Discussion
Using Javascript to trigger sending an email
The relevant JavaScript in the code snippet provided is:
var to = "Recipient"; // Can also be a variable
So your mailto_link is doing what it's being told to: giving the variable "to" the value of "Recipient." That "Recipient" needs to be replaced with a reference to the variable you're using to store the user's inputted email address.
If at the beginning of the course the learner's typed email is stored in a variable called learnerEmail, then your code should read
var to = getVar('learnerEmail');
- DanEccleston-c113 days agoCommunity Member
That has worked a treat.
Can I ask one more question?
In the body of the email, ideally I want the question on one line , then the answer selected underneath..
How would I do that?
So say the first question in the example above is : Confirm Role.. the answer uses variable 'Role_Output'
If I can get one line done , I can duplicate it for the rest!
Thanks so much!- AndrewBlemings-12 days agoCommunity Member
I confess I'm less sure for your implementation. The easy answer is that new lines can be created in strings of text using the \n "new line escape character." So if I had a variable foo and I assigned it the value '123\n456', it should print out as
123
456
I'm much less familiar with your encodeURIComponent function, but I expect your "var bodyContent =" assignment can fit in a new line escape between the two strings of text.
var bodyContent = getVar('Role_Question') + '\n' + getVar('Role_Output');
Related Content
- 1 year ago