Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Hiding elements using external JavaScript

Participant ,
May 10, 2016 May 10, 2016

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!

2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , May 10, 2016 May 10, 2016

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

Translate
People's Champ ,
May 10, 2016 May 10, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 10, 2016 May 10, 2016

Thank you very much!  Perfect!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 20, 2016 May 20, 2016

TLCMediaDesign

Could you help me to get this code work. So far I was not able to do it.

I was able to get working the code that starts with window.cpAPIInterface. Ex: window.cpAPIInterface.next(); (Mainly the stuff that is listed in Common JS interface article)

But, I could not get working the code that starts with window.parent.cp. Ex: window.parent.cp.hide(e.Data.itemname,+6);

What I did so far:

I have a smarshape called "numberBox". It is on the slide number 6 (no slide name or title).

The code that I tried, but it did not work:

window.parent.cp.hide("numberBox",+6);

window.parent.cp.hide('numberBox',+6);

window.parent.cp.hide('numberBox', '6');

... and all other possible variations

Could you please write the code that would hide it.

Thanks a lot in advance

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 23, 2016 May 23, 2016

window.parent.cp.hide("numberBox");

There is only one argument to pass into the cp.hide() function. It the property name of the element. Using the comma you are creating 2 arguments.

It you want to make the code a little more dynamic for like names on successive slides you could use:

window.parent.cp.hide("numberBox" + window.parent.window.cpInfoCurrentSlide);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 23, 2016 May 23, 2016

TLCMediaDesign

Thank you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 10, 2016 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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 10, 2016 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 10, 2016 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");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 10, 2016 May 10, 2016

it's the same as with the next button.  The caption is created in Captivate and is assigned a name of Title_2 then I need to change the text inside of it using a custom function inside index.html with a value that gets pushed from an HTML5 animation.  All that works great, I can assign new values to the Title_2, it shows up in console.log if I call it, etc but I cannot figure out how to get actual text displayed inside that caption.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2016 May 10, 2016

Because you have to insert the variable in the text container (shape or caption), using the X button in the Character part of the Properties panel. Maybe I misunderstand, but you seem to label the container with 'Title_1', not the embedded variable?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 10, 2016 May 10, 2016

You need to define a variable in Captivate, v_Title_2. Then for the text in the text caption: $$v_Title_2$$.

Then you can populate the variable from within the animation:

window.parent.window.v_Title_2 = :"Your new Title"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2016 May 10, 2016

If you want that text to be displayed in a text container, you'll have to put a user variable in that text container and populate that variable with the JS.

Have a look at this help page:

Common JS interface

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 10, 2016 May 10, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 11, 2018 Apr 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 11, 2018 Apr 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";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Apr 11, 2018 Apr 11, 2018

It's much easier to use cp.hide("Text_Caption_69");

Let Captivate do the work of getting the element by id for the normal and canvas element as well as the re-wrap element.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 11, 2018 Apr 11, 2018

100% agree with that...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 15, 2018 Apr 15, 2018

Do you know how i can make a text caption visible?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 15, 2018 Apr 15, 2018
LATEST

cp.show ("Text_Caption_69");

First reflect if you really need to use JS? So much easier with simple commands, advanced/shared actions which are converted to JS on runtime. I totally agree that not everything can be done with those actions, but for simple hide/show JS is overkill. If you are on CP9 or CP2017, have a look at multistate objects. Since they appeared I will not use Show/Hide that much anymore...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources