Explore the community Forums Lectora Lectora Questions & Answers Reset all Entry field variables

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #340421 Score: 0
    Profile photo of mallow76
    mallow76
    Member
    beginner
    intermediate
    contributor
    wise owl
    curious george
    23 pts
    @mallow76

    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.

    #341798 Score: 0
    Profile photo of mallow76
    mallow76
    Member
    beginner
    intermediate
    contributor
    wise owl
    curious george
    23 pts
    @mallow76

    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.

    #341801 Score: 0
    Profile photo of Tim K
    Tim K
    Member
    contributor
    beginner
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    wise owl
    curious george
    Group Member
    307 pts
    @timk

    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.

    #341803 Score: 0
    Profile photo of mallow76
    mallow76
    Member
    beginner
    intermediate
    contributor
    wise owl
    curious george
    23 pts
    @mallow76

    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?).

    #341805 Score: 0
    Profile photo of mallow76
    mallow76
    Member
    beginner
    intermediate
    contributor
    wise owl
    curious george
    23 pts
    @mallow76

    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.

    #341811 Score: 0
    Profile photo of Tim K
    Tim K
    Member
    contributor
    beginner
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    wise owl
    curious george
    Group Member
    307 pts
    @timk

    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

    #341858 Score: 1
    Profile photo of Darrel Somoza
    Darrel Somoza
    Member
    contributor
    friend finder
    beginner
    intermediate
    junior moderator
    advanced
    wise owl
    curious george
    profile
    199 pts
    @Klaatu

    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.

    This post has received 1 vote up.
    #341861 Score: 0
    Profile photo of Darrel Somoza
    Darrel Somoza
    Member
    contributor
    friend finder
    beginner
    intermediate
    junior moderator
    advanced
    wise owl
    curious george
    profile
    199 pts
    @Klaatu

    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?

    #341866 Score: 0
    Profile photo of Tim K
    Tim K
    Member
    contributor
    beginner
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    wise owl
    curious george
    Group Member
    307 pts
    @timk

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

    #341886 Score: 0
    Profile photo of Peter Jackson
    Peter Jackson
    Member
    beginner
    intermediate
    advanced
    friend finder
    contributor
    junior moderator
    wise owl
    group mod
    entry
    winner
    17 pts
    @pjackson2462

    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 < maxEntry; i++) {
    number = (“0000” + i).slice(-4);
    varName = “VarEntry_”+number;
    saveVariable(varName,varValue,0,titleName,false, false);
    }

    HTH

    Regards, Peter

    #341911 Score: 0
    Profile photo of mallow76
    mallow76
    Member
    beginner
    intermediate
    contributor
    wise owl
    curious george
    23 pts
    @mallow76

    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.

    #341925 Score: 2
    Profile photo of Tim K
    Tim K
    Member
    contributor
    beginner
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    wise owl
    curious george
    Group Member
    307 pts
    @timk

    It can be done with Darrels code.

    This post has received 2 votes up.
    #341932 Score: 0
    Profile photo of mallow76
    mallow76
    Member
    beginner
    intermediate
    contributor
    wise owl
    curious george
    23 pts
    @mallow76

    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.

    #341977 Score: 0
    Profile photo of Darrel Somoza
    Darrel Somoza
    Member
    contributor
    friend finder
    beginner
    intermediate
    junior moderator
    advanced
    wise owl
    curious george
    profile
    199 pts
    @Klaatu

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

    #342301 Score: 0
    Profile photo of mallow76
    mallow76
    Member
    beginner
    intermediate
    contributor
    wise owl
    curious george
    23 pts
    @mallow76

    @timk <span class=”handle-sign”>@</span>Klaatu

    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?

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic.