Use Javascript to pass a variable from one title to another
July 20, 2016 12:00 AM
I am very new to Lectora and Javascript, but I am familiar with other coding languages.
For the training I am conduction I am not placing the lessons into an LMS. I created a Menu title that will allow the user to select option and then launch a series of lessons (independent titles). Each lesson presents slightly different information based on the selections made in the main menu. We are trying to keep the lessons separated out in multiple titles for sustainment purposes.
I thought I may create and set a cookie to allow me to pass the variable. This idea seemed simple, but I can't seem to get it to work.
another idea would be to add / get a value from the session storage. This too seemed simple, but I can't get it to work.
I have a feeling I am missing a basic step.
I added this as a HTML extension at the top level
undefined
for (i = 0; i undefined i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name) {
return unescape(y);
}
}
}
function cssSelected() {
var cssSelected = $('#myList')[0].value;
if (cssSelected !== "select") {
setCookie("selectedCSS", cssSelected, 3);
}
}
$(document).ready(function() {
$('#myList')[0].value = getCookie("selectedCSS");
})
undefined
Then call one of the functions on a button press using a javascript
setCookie("Role", 3, 1);
undefined
I have tried several variations of this, but no luck.
Discussion (2)
Your cookie setting/getting functionality seems to work fine: https://jsfiddle.net/t88Lnmov/
Maybe there is a problem with the cssSelected function. I cannot say because it queries your HTML, which you aren't sharing. In particular, it is important to understand what element you are trying to get by the #myList id?
A should not have added that function as I am not calling it. I have been able to get the menu title to write the cookie. by loading the "setCookie" function and the "getCookie" function into a my.js file that I use a undefined in the header. then placing a javascript action on a menu selection:
setCookie("Role", "3", 1);
I am just having a problem getting the target title to read the cookie..
I placed the same undefined
my user variable name in the lectora title that I am trying to set is "_Role" the variable in the cookie is called "Role"
The target titles are place in a subfolder of the menu so they should be able to access the cookie (or at least that is my understanding).
Discussions have been disabled for this post