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

Javascript for Text Entry Box to API for reporting

Participant ,
Nov 30, 2016 Nov 30, 2016

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.student_response (SCORM 1.2)

     cmi.interactions.id (SCORM 1.2)
     cmi.objectives.id (SCORM 1.2)

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!

TOPICS
Advanced
1.0K
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 06, 2017 May 06, 2017

Hi,

Did you ever find a solution for this?

Thanks.

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
Contributor ,
May 07, 2017 May 07, 2017

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.

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 07, 2017 May 07, 2017

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.

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 08, 2017 May 08, 2017

I think you are going to need to use the cmi.interactions method.

the cmi.comments are appended, not rewritten.

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 11, 2017 May 11, 2017
LATEST

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.

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