Reset all Entry field variables

Hi - Can anyone advise me about how i could easily reset the variables for all entry boxes that I have used within my title?

I have a system simulation that uses a large number of these to replicate various parts of the system however when people repeat the scenario (as they are encouraged to do) the values remain. I know I can modify the value of each individual variable to make it reset but it would be way easier to do them all at once. 'Reset all variables' won't work because i use a number of other variables to track various other things.

Any help appreciated.

Discussion (15)

If you put 12 text inputs on one page you can use this script to set all of the back to null. Change the number 12 in the script to the number of text inputs on the page. A few things to keep in mind. Text input variables are assigned consecutively starting at Entry_0001. This script, as is, will not work on multiple pages however you can alter the loop to match the Entry_XXXX variable names and reuse it. Anothe rhitng this script will not do is remove what the participant typed in originally. That you will have to handle either with another script or actions.

for (i = 1; i < 12; i++) {

number = ("0000" + i).slice(-4);

test = "VarEntry_"+number;

this[test].set('');

//console.log(test + " = " +this[test].value+'\n');

}

You can remove the comment to see the variable vaues reset in the console log if you wish. My intention here was not to provide the final answer but to give you and the others idea's. If there's a will there's almost always a way. Unfortunately, I do not have the free time to code you a drop in solution at this time. Hope this helps.

I do have a 'launch pad' page that all of the scenarios are accessed from and currently I have an 'on show' action that runs through all of the entry box variables and resets them. This works but depends on me (remembering and) manually adding any new text fields into this action group. Just hoped there would be an automatic way of managing this but maybe there's not.

You could do what Trivantis does:

saveVariable(varName,varValue,0,titleName,false, false);

Where:

  • varName = VarEntry_0001
  • varValue = the new value to be saved
  • titleName = the name of your title, lowercase, spaces replaced with _ (underscore)

So using Darrel's code above and knowing the number of entry fields you can reset all field variables, in fact you could use a greater number than the actual number of entry fields as the saveVariable() function will simply create the extra variables. Your code would look like:

var maxEntry = 55;

var varValue = '';

var titleName = 'the_name_of_your_title'; //this must be changed:-)

for (var i = 1; i undefined i++) {

number = (“0000” + i).slice(-4);

varName = “VarEntry_”+number;

saveVariable(varName,varValue,0,titleName,false, false);

}

HTH

Regards, Peter

You'd need one form per page with entry fields, but the form can only be reset on the same page.

I don't know a way to target several variables at once, at least none that is less work than creating an action group with one action for each entry field.

A way to achieve it could be to create a button with a "Reset all variables" action. Find the action in the source code of the page and copy it to a "Run javascript" action. Remove all lines from the code that don't refer to entry field variables. Mind that modifying the variable won't empty entry fields on the same page. Then you can remove the button.

Tim

hm, good start for 2017, just found something, I've been thinking about for years... and it's only the 4th

Anyone? Thinking there must be some js trickery that can achieve this.

i should point out that it is when people repeat scenarios within a session that the problem exists. The variables are not retained and so the variables are cleared after the module is exited.

The only thing I can think of, would be to add all the entry fields to a form and reset the form instead of all the separate variables.

Thanks for replying Tim. The entry fields are spread over several chapters each with 40+ pages so don' t think there is a way to make this work using forms (is there?).

Tim, I'm grabbing the variables in a local scope. That's why it doesn't work across multiple pages. I believe you showed me, using Window[], how to access all variables globally. Perhaps you can alter the script above to create a one click solution that Mallow76 could use on the last page with entries?

It can be done with Darrels code.

The most entry boxes I have on any one page is only 3 so i don't think any page level solution will help me too much. I have around 25 entry fields spread over 40 pages in each of my scenarios (of which there are between 4 and 8) so it is a global solution that I would ideally be finding. From your suggestions though it does look like something might well be possible so I will have a play about and see how I get on.

Many thanks for your replies.

Outstanding! Great job Tim! Definitely saving this one for future reference.

Perfect. Many thanks indeed for this Tim (and Darrel).

I don't need the bit of code that resets the fields (though it is good to see!) as this will run 'on show' of my landing page where there are no entry fields. I've set up a separate version of it to work with resetting my radio buttons too.

@timk undefinedKlaatu

This solution worked great in my testing but now I have put the title in an AU for publishing to SCORM it no longer works. Do you know why this doesn't work in this situation and might there be a way it can be made to work?

I tested my example in moodle (Scorm 1.2) and it's working without issues... Did you change anything?

Discussions have been disabled for this post