Skip to main content
Participant
February 10, 2021
Answered

JavaScript in a button not functioning

  • February 10, 2021
  • 1 reply
  • 487 views

Hi,
I'm attempting to add JavaScript to a button so that when the trainee hits it, it will open an email.  My I.T. department has provided me with the language of the script. 

function () {
var subject = "Subject";
var body = "Body";
window.open('mailto:sampleemail@yahoo.com?subject=subject&body=body');
}

I placed it into the Script_Window and put the action as Execute JavaScript.  I then publish it as HTML, but when we get to the button and hit it, the training just continues on without opening the email.  I've done everything the user guide says and am told the script is correct.  What else am I missing?  

Thanks!

This topic has been closed for replies.
Correct answer RodWard

The JS code is incomplete.  You've described a function but not given it a name, and then you haven't called the function.  Try this:

-------------------------------------

function myFunct () {
var subject = "Subject";
var body = "Body";
window.open('mailto:sampleemail@yahoo.com?subject=subject&body=body');
}

myFunct ();

-----------------------------------

However, using JS in this case was actually quite unnecessary (though it does make it easier to alter the subject and body text).  All you had to do was set the button to execute the Send Email To action and then enter this code in the field provided for that action:

-----------------------------------------

mailto:sampleemail@yahoo.com?subject=subject&body=body'

--------------------------------------

The result is the same.  When ever using JS it's usually best to make sure you are viewing the content via a web server, not just locally.  With Captivate, just use the Preview > HTML5 in browser option to see the content in a temporary web server environment.

1 reply

RodWard
Community Expert
RodWardCommunity ExpertCorrect answer
Community Expert
February 11, 2021

The JS code is incomplete.  You've described a function but not given it a name, and then you haven't called the function.  Try this:

-------------------------------------

function myFunct () {
var subject = "Subject";
var body = "Body";
window.open('mailto:sampleemail@yahoo.com?subject=subject&body=body');
}

myFunct ();

-----------------------------------

However, using JS in this case was actually quite unnecessary (though it does make it easier to alter the subject and body text).  All you had to do was set the button to execute the Send Email To action and then enter this code in the field provided for that action:

-----------------------------------------

mailto:sampleemail@yahoo.com?subject=subject&body=body'

--------------------------------------

The result is the same.  When ever using JS it's usually best to make sure you are viewing the content via a web server, not just locally.  With Captivate, just use the Preview > HTML5 in browser option to see the content in a temporary web server environment.

Participant
February 11, 2021

Thank you for your reply!  I really appreciate your suggestions.  JavaScript is a foreign language to me and I assumed my I.T. would provide what was needed. 

 

So, I'm trying to use the Send Email To option that you mentioned with the following:

mailto:sampleemail@yahoo.com?subject=Completed Endangered Children Training&body=This email certifies that I have completed the Endangered Children course with a minimum passing score of 80% on this date. 

 

But then I get an error message that "The email specified for 'Success Action' is invalid. Your changes cannot be saved."

 

I'm asking my I.T. for help, but they don't know Captivate.  And I don't know if this is a Captivate issue or what.  Do you have any additional thoughts you can share?  I really need this to work and appreciate the help!