Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Strange behaviour when $('#movenextbtn').click() and relevance used?

More
9 years 4 months ago - 9 years 4 months ago #114680 by garf
Hi all,
I have to apologize in advance, I'm not getting anything in my preview post window for this post...so in case it comes out looking strange!


I'm stumped on this one.. and I think it's probably something simple..but I can't see it. I've created a survey with a running timer over the entire survey and 5 groups and group index turned on.

-Group 1 contains a numeric question defaulted to = 0 called "timedout" and another regular question with relevance set to with relevance set to timedout == 0.
-Groups 2 to 4 contain 1 question each with relevance set to timedout == 0 .
-Group 5 has some questions that hold recap data and are hidden. One more equation type question confirms if the user wants to leave the survey before answering all the questions ie if(TotalAnswered == 4, "Completed message","incomplete message") and is not hidden, but a relevance of (timedout==0)

In the template.js, I have something like this:
Code:
function() { // what to do after timer expires
            $('#answer144155X1463X6926').val(1); // Set "timedout" relevance question
            $('#answer144155X1463X6947').val(sessvars.ctime.current); //default is set to 0
            alert ($('#answer144155X1463X6926').val());            
            $('#movenextbtn').click();
            $('#movesubmitbtn').click();
        });

If I'm on group 1 to 3 and the timer expires, I can see the alert value of "1" pop up as the value behind my relevance question "timedout". It behaves as you expect, moves me to the end of the survey and submits. All invisible! Perfect. However, if I'm on group 4, I get Undefined in the alert and moved to group 5 with the equation question displayed. I still have to click submit.

I can't figure out how or why for the life of me. I suspect it's the sequence in events firing...but can't be sure? For some reason, group 5 can't see the value behind the equation I've set?
Code:
$('#answer144155X1463X6926').val(1);

Any ideas are greatly appreciated!

Gary
Last edit: 9 years 4 months ago by garf.
The topic has been locked.
More
9 years 4 months ago #114681 by garf
To add to the above...
I just noticed... if I'm on any other group other than group 1 where "timedout" resides, the groups and questions following can not see it. Is this a design feature or a bug I'm seeing?

Thanks,

Gary
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 4 months ago #114691 by tpartner
JavaScript can only work within the current page. You cannot use it to set the value of an element in a previous group.


.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
9 years 3 months ago #114718 by garf

tpartner wrote: JavaScript can only work within the current page. You cannot use it to set the value of an element in a previous group.


.


Thanks Tony, makes sense.

For some reason I thought LS carried these forward. Given this, can EM read session variables you might set in the template.js file? I think EM is able to set the value of a previous question, so that might be a fix? Or, do I need to put a hidden question in each group and set each value via script in the template.js?

Many thanks again for the clarification!
Gary
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 3 months ago #114719 by tpartner
Expression Manager has no access to template.js and vice versa.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: garf
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose