Skip to main content
xtd8865
Known Participant
December 26, 2017
Answered

Accessing variables created in JS

  • December 26, 2017
  • 2 replies
  • 482 views

Hi,

I have 2 questions:

1. How I could access a variable assigned via a Text Entry Box by a user in a JS script? For example a user fills in an entry box (and therefore assigning a variable accessible in the Captivate interface by $$v_my_variable$$), and I would like to access the value within a js window to do some JS calculations on it.

2. How do I do the opposite. I generate some values within a js (eg. generating a random number and assigning it to a variable, eg:

var number = alert(Math.random());

How do I access $$number$$ from a text box or a smart shape in Captivate?

Thank you

    This topic has been closed for replies.
    Correct answer Stagprime2687219

    I have been successful at manipulating variables with javascript by simply using

    window.variableName

    For example, I have a variable called points. The value of this variable is created by concatenating two other variables - red and black.

    The javascript looks like this:

    window.points=String(window.black).concat(red);

    Perhaps this example may be useful in advancing your project.

    2 replies

    Stagprime2687219
    Stagprime2687219Correct answer
    Legend
    December 26, 2017

    I have been successful at manipulating variables with javascript by simply using

    window.variableName

    For example, I have a variable called points. The value of this variable is created by concatenating two other variables - red and black.

    The javascript looks like this:

    window.points=String(window.black).concat(red);

    Perhaps this example may be useful in advancing your project.

    xtd8865
    xtd8865Author
    Known Participant
    December 26, 2017

    Thanks. That's even more informative points.

    Lilybiri
    Legend
    December 26, 2017

    I am not a JS expert, but maybe these articles I wrote for newbies like myself, does explain how to exchange variables using JS. I did use TEB's:

    Playing with Numbers - part 1 - Captivate blog

    Playing with Numbers - part 2 - Captivate blog

    xtd8865
    xtd8865Author
    Known Participant
    December 26, 2017

    Thanks - I found what I needed in the posts that you linked.