Copy link to clipboard
Copied
Would someone be able to advise on writing javascript to report user input text from a text entry box to API for reporting?
Disclaimer: I do no know much about javascript.
What I do know:- I am using SCORM 1.2
- My LMS allows me to call the following API
cmi.comments (SCORM 1.2)
cmi.interactions
cmi.interactions
cmi.objectives
My TEB for my test are creatively named
text_entry_box_1
text_entry_box_2
What I do not know:
How do I send the value entered in text entry box to an API to report on this?
If more than one Text Entry Box, how does this effect the javascript?
Where do I execute the Javascript (upon entering slide, exiting slide, clicking submit button?)
I found something on one of the forums that looked close:
SCORM_CallLMSSetValue('cmi.comments', 'Hello');
To me, this looks like it would set the value of cmi.comments to Hello by default. I would need that to be the value of text_entry_box_1
Any help is appreciated!
Copy link to clipboard
Copied
Hi,
Did you ever find a solution for this?
Thanks.
Copy link to clipboard
Copied
I do this all the time reporting into an xAPI (tincan). Here is a few things to try and a general overview. I am not familiar with SCORM_CallLMSSetValue(), as I don't use Scorm (rather tincan), but I would think if all you need to pass a value you might be able to do this directly from Captivate.
Try thi:s
var val_one = window.cpAPIInterface.getVariableValue("text_box_entry_1"); //This grabs the value from captivate
SCORM_CallLMSSetValue('cmicomments',val_one);//passes your value into API
If you want to see if it worked (or at least didnt give any errors), open the console in your browser. For instance if you were to get back something to the effect of SCORM_CallLMSSetValue() is not a function, your .js library for this is not loaded. (Again I don't use SCORM, but my asumption is when you do Captivate automatically loads that library).
Also just winging it here, but I would think you could also put in:
console.log(SCORM_CallLMSGetValue('cmicomments');
and the console would show the value you assigned
How to achieve embedding javascript:
The CP Javascript window is a horrible interface at best, so I try to do as little of my .js as possible in CP, as it is much easier to edit when it lives outside of captivate. You can manipulate after publish if there are errors or things you need to check/debug. Anything in captivate .js window requires a republish (while it is manipulatable in the CPM file it is not easy).
Here is a quick walkthrough of the need to know info for the same example.
Captivate generates a CPM.js file that is the engine for captivate. You either have to add your .js to this file, or create a separate file and add the file to the loader the index.html that is generated. There is a loader towards the bottom in the index file, make sure you load it prior to CPM file so it is loaded and available.
To get the variables from captivate to your javascript you can go 2 ways. Either way you will want to put what your API request in a javascript function. You can also grab it directly in external .js the same way, but I prefer this way as you can always modify what you are passing in from Captivate and one code function will work when added to any captivate and can be reused.
Next you will need to call that function from your captivate piece so if we created a sendData function in javascript you would need to invoke that function from captivate. Do this using java script window in captivate, you would just embed sendData(), as javascript when your captivate trigger happens.
Let's talk about how you grab the info in Cp and pass it over.
In Captivate - In your javascript window in captivate you need to grab the values and assign them to a variable to pass.
var val_one = window.cpAPIInterface.getVariableValue("text_box_entry_1"); //This grabs the value from captivate
sendData(val_one);//this calls your .js function.
In the javascript -
function sendData(value){
SCORM_CallLMSSetValue('cmi.comments', 'value');
}
One last thing to consider is do you need validation?...In otherwords are typo's or any value ok, or do you need a strict value?
I write these scripts all day long for different functions, let me know if you have more specific questions. It took me months to 'crack the code' so I am always happy to help others in the learning curve.
Copy link to clipboard
Copied
Thanks Behr,
I was starting to crack this. Writing to cmi.comments works well. Straight forward with the same code you mentioned above.
Unfortunately, I just worked out that SCORM 1.2 (Moodle default) has a character limit of ~255.
The students answers can be much longer than this. So now I will look at other options. Maybe it is time to start pushing TinCan.
Something else to learn. But probably more useful going forward.
Thanks.
Copy link to clipboard
Copied
I think you are going to need to use the cmi.interactions method.
the cmi.comments are appended, not rewritten.
Copy link to clipboard
Copied
Setting cmi.comments (SCORM variable) with Javascript in Captivate 8? I did find a solution on this thread. A very nice person wrote the javascript for me. Works great.