HOME ➔ SUPPORT ➔ Community ➔ General CourseLab issues ... JavaScript Variables
JavaScript Variables
  View type:
I appologize if this question was already answered, however I cannot seem to search through the threads anymore.

I have placed a JavaScript code both in the module and in the module.js file. It simply produces a random whole number variable (the Math.random()*10 will not produce a whole number from what I can see). However, I want to pass that variable to the module that I am using. I have poured over the Internet and through the User Guide to find a way to pass variables from the module to JavaScript and back, but to no avail. Can anyone point me in the right direction?
 
maybe this can be a small piece of the solution.
Once I figured out I can make a runtime variable myName and use it in javascript by referencing g_arVars["myName"];

I assume the opposite is also true, which means (try):
- make a variable myRandomNumber
- call your javascript function which assigns a random number to g_arVars["myRandomNumber"]
- use myRandomNumber

Please let us know if it works [;)]
 
 
I'm not clear with this, anybody can give sample ?
 
 
 
We using an external (to the module but bundled with it) random number generator script here??
OR
Writing it into the module JS as an after publishing mod??
First idea sounds cleanest.
AND
Anyone want to put together an annoted sample?
 
 
 
 
I apologize if this question comes again, my project want to write data from Slide to file text, use by javascript. question is how to pass variable from CL to Javascript. this is my project.

in the slide I have 2 inputbox and 1 Button.

Run-time variable name : name
Variable Scope : Current Module

Run-time variable name : user_id
Variable Scope : Current Module

Button Action
JavaScript ( WriteFile();)

in the modul,js

var name;
var user_id;

function WriteFile()
{
var Scr = new ActiveXObject("Scripting.FileSystemObject");
var CTF = Scr.CreateTextFile("C:\\Data.txt", true);

CTF.WriteLine(name);
CTF.WriteLine(user_id);

CTF.Close();
}

data from InputBox not pass to variable in javascript.

if I change in javaScript, i Wrote to variable. like this

name = "Binsar";
user_id = "binsar1234";
WriteFile();

and I open file C:\\Data.txt, i found
Binsar
binsar1234

so my clear question is, how to pass data in variable from CL to JS and conversely

need full sample, Thanks![:confused:]
 
 
This worked PERFECTLY! Thank you so much!

Now, I do have another somewhat related question. I want to take that random number and use it to go to a specific slide (or frame). Is this possible? I have tried using the GOTO and CALL actions and placing the varible name in the frame box (after going through and renaming the frames in my module to just the numbers). It didn't work, so I was wondering if there might be a way of doing this that someone might know.
 
 
 
Take care, the solution might not work with newer versions of CL because its a hack [;)]

One way to address your second problem is to make an action
if (#variable == 1)
(space)goto page 1
etc.

Another hack might start in courselab.js
[:cool:]
 
 
 
 
OK, please forgive my ignorance, but when I create an item and go into the action of the item and select JavaScript, how do I call the functions that are listed in the courselab.js file? The g_arVars array was easy to work with, but I'm lost on the functions.
 
 
 
 
 
LOL@multiple posts

If I remember well, you can just call these functions as you would call a function like alert("my message");
I'm not sure though and it will take quite some days before I'm at work again, where I have a file I tried something like that.

The big problem of course is the right parameters and also that using these functions might not work in future versions. They might just change the name of these functions and you're lost.

I suppose best is to use the if ... goto construction and ask Slav to add Goto #variable in the next version.

There is an old post which might help you. Google for 'courselab CallMethod(sType, sMethod, oArg)'.
[:D]
 
 
 
 
 
 
I just wanted to tell you that your suggestion really helped. I found a function called OpenSlideById(sstring); that helped me to creat a jump to the random slide numbers that were picked. No I can have a whole module of questions and simulations and have it randomly pick a set amount of questions for each student. Thank you all for your help on this (and I promise not to repost this several time).
 
 
 
 
 
 
 
Your message is very valuable, I didn't know about this function OpenslideById(sstring); I copy it to my 'personal backup' [;)]
Thanks!

AFAIK such a post might be posted twice! [:D]
 
 
 
 
 
Sorry about the extra re-posts, I was a moron and just hit the refresh butoon on the page where I submitted instead of going to a clean page. What an idiot I am.
 
 
 
 
OK, please forgive my ignorance, but when I create an item and go into the action of the item and select JavaScript, how do I call the functions that are listed in the courselab.js file? The g_arVars array was easy to work with, but I'm lost on the functions.
 
 
 
 
OK, please forgive my ignorance, but when I create an item and go into the action of the item and select JavaScript, how do I call the functions that are listed in the courselab.js file? The g_arVars array was easy to work with, but I'm lost on the functions.
 
 
 
 
OK, please forgive my ignorance, but when I create an item and go into the action of the item and select JavaScript, how do I call the functions that are listed in the courselab.js file? The g_arVars array was easy to work with, but I'm lost on the functions.
Subject:
Message options
No additional options