Skip to main content
Inspiring
May 10, 2016
Answered

Hiding elements using external JavaScript

  • May 10, 2016
  • 4 replies
  • 2873 views

Hello!  Hopefully an easy question here.

I have buttons in Captivate 9 that I need to hide/show using an external JavaScript that comes from an imported HTML5 animation.

Currently, I am trying to do it in this manner (although unsuccessfully):

The next button is named "next_button_2" since it's on slide #2.

Inside of index_scorm.html I added a function:

     function disableNext()

     {

          var slideNumber = window.cpApIInterface.getCurrentSlideIndex(); //to get the current slide number

          var nextButton = $("#next_button_" + slideNumber);

          //then I tried using code like nextButton.style.visibility  = "hidden"; or nextButton.hide(); etc, but nothing seems to take.  I'm sure I'm not pointing to the element           properly.

     };

Inside imported HTML animation I have the following code:

     window.onload = function disableButton()

     {

          parent.disableNext();

     };

I know the functions are talking to each other as I've experimented with passing variables, I know the slideNumber variable is assigning a right number.

How do I point to the right object to hide/unhide it?

Thank you!

    This topic has been closed for replies.
    Correct answer TLCMediaDesign

    window.parent.cp.hide("next_button_" + slideNumber)

    4 replies

    Participating Frequently
    April 11, 2018

    Hey guys! I am trying to hide a text caption in Ccaptivate 10. I am using this code: document.getElementById("Text_Caption_69").style.visibility="hidden"; But it is not working. Can you give me any suggestions? The elements are in fluid box

    sabre123
    Participating Frequently
    April 11, 2018

    If you really want to hide an object in this manner, try adding a "c" to the end of the element's ID to target the canvas element:

    document.getElementById("Text_Caption_69c").style.visibility="hidden";

    anton9800Author
    Inspiring
    May 10, 2016

    Ok, makes a whole lot more sense now!  Thank you very much, TLCMediaDesign and Lilybiri!

    TLCMediaDesign
    Inspiring
    May 10, 2016

    Also if you just want to disable/enable:

    window.parent.cp.disable("next_button_" + slideNumber)

    window.parent.cp.enable("next_button_" + slideNumber)

    anton9800Author
    Inspiring
    May 10, 2016

    Thank you!  Similarly, how would I pass a value to a text caption?

    something like

    var myTitle = "Hello!"

    document.Captivate.cpEISetValue("Title_2", myTitle);

    And for that matter - is there an API I can look at?  Thank you again!

    TLCMediaDesign
    Inspiring
    May 10, 2016

    The only real reference for the API is:

    Common JS interface

    There's only so much in there. The rest is from dissecting the CPM.js.

    All of the Captivate variables are in the window object, so unless you are using SWF and HTML5, I just use the window:

    window.Title_2 = "Hello";

    If you want to set using the interface:

    window.cpAPIInterface.setVariableValue("Title_2", "Hello");

    TLCMediaDesign
    TLCMediaDesignCorrect answer
    Inspiring
    May 10, 2016

    window.parent.cp.hide("next_button_" + slideNumber)

    anton9800Author
    Inspiring
    May 10, 2016

    Thank you very much!  Perfect!