Page 1 of 1

Saving JavaScript

Posted: Mon Jan 28, 2013 3:19 pm
by Latchezar Mladenov

Hi, in my quiz game i have 4 levels with 21 questions and when I guess 21 questions of one level the app run the following javascript:

var button = document.getElementById("j_399").childNodes[0];
button.childNodes[0].innerHTML = "Level 2 - unlocked";

document.getElementById("j_399").disabled = false;

And everything runs correctly. But when I exit the app and start it again the javascript has not saved. Is there any method to save the function when I exit and start again.


Saving JavaScript

Posted: Mon Jan 28, 2013 5:46 pm
by Kateryna Grynko

Hello,

We cannot reproduce your problem.

Does Run Javascript action disappear from the project?
Can you see other actions for this component in the editor?
Or you are able to see Action in the editor, but Javascript won't work in test?


Saving JavaScript

Posted: Mon Jan 28, 2013 8:06 pm
by Latchezar Mladenov

No, JavaScript run correctly when a button is clicked. I want to save the function which is clicked once for all the time not only for the resent game


Saving JavaScript

Posted: Tue Jan 29, 2013 8:32 am
by Maryna Brodina

Hello!
You can save to localStorage value (like indication that first test passed)

localStorage.setItem('test1Passed', 'true');

Then on page Load you can check whether test passed. If so - run next JS:

codevar isTest1Passed = localStorage.getItem('test1Passed');
if (isTest1Passed === "true") {
var button = document.getElementById("j_399").childNodes[0];
button.childNodes[0].innerHTML = "Level 2 - unlocked&quot

document.getElementById("j_399").disabled = false;
}/code