Skip to main content
Known Participant
May 21, 2018
Answered

Text entry box variable and JavaScript

  • May 21, 2018
  • 2 replies
  • 1011 views

I've been fooling around with JavaScript and, with some excellent assistance from this forum, have made some headway. I have what looks like a very simple problem, but for some reason I can't get in to work. I have a text entry box with a variable, let's call it v_capVble. My On Success action is to execute a simple JS: JSVble = window.cpAPIInterface.getVariableValue('v_capVble');. So I'm assuming that when I enter something in the text entry box it will be stored in the JavaScript variable: JSVble.

On the next slide I have the following JavaScript:

If (JSVble === "TxtEntered") {

     cp.Show ("SmartShape");

}

I'm assuming if I enter (in this case) TxtEntered, the smart shape (SmartShape), which was hidden, will appear. But alas, that isn't happening. Again, this seems pretty basic but for JavaScript newbies like me, what frequently seems simple is actually more involved. Again, I'm just fooling around, but if anyone has a quick solution it would be appreciated. Thanks.

This topic has been closed for replies.
Correct answer Stagprime2687219

Try this, changing variable names as necessary.

But just have this be your OnSuccess action

if (window.v_capVble=="TxtEntered") {

cp.show("SmartShape");

}

Basically just changing the three equal signs to two and using the syntax of window.variableName rather than just variableName.

It also helps if you have created the variable in Captivate as well, especially if you want to use it across slides.

2 replies

TLCMediaDesign
Inspiring
May 21, 2018

If there is already a variable associated with the text entry, there is no need to assign it to another variable. So you really don't need to execute JS on success.

If (window.v_capVble === "TxtEntered")

{

     cp.Show ("SmartShape");

}

Lilybiri
Legend
May 21, 2018

I don't understand why this would need JS,  instead using "Show Smartshape" as simple action for the Success event of the validated TEB. It is great to extend Captivate's functionality by JS, but I would never do that for such a simple action.  Isn't Captivate a rapid authoring tool? Lot more useful things to do with JS, where CP is not capable of handling it within the provided features.

Known Participant
May 21, 2018

You are right - this could easily be done in Captivate. I was just trying to come up with a scenario where I could implement a Switch statement (i.e., Case 1, Case 2, etc.). Just trying to flex my feeble JS muscles in case I encounter a circumstance where this could be useful.

Stagprime2687219
Stagprime2687219Correct answer
Legend
May 21, 2018

Try this, changing variable names as necessary.

But just have this be your OnSuccess action

if (window.v_capVble=="TxtEntered") {

cp.show("SmartShape");

}

Basically just changing the three equal signs to two and using the syntax of window.variableName rather than just variableName.

It also helps if you have created the variable in Captivate as well, especially if you want to use it across slides.