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

More
2 years 11 months ago - 2 years 11 months ago #114680 by garf
garf created the topic: Strange behaviour when $('#movenextbtn').click() and relevance used?
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:
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?
$('#answer144155X1463X6926').val(1);

Any ideas are greatly appreciated!

Gary
Last Edit: 2 years 11 months ago by garf.

Please Log in to join the conversation.

More
2 years 11 months ago #114681 by garf
garf replied the topic: Strange behaviour when $('#movenextbtn').click() and relevance used?
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

Please Log in to join the conversation.

More
2 years 11 months ago #114691 by tpartner
tpartner replied the topic: Strange behaviour when $('#movenextbtn').click() and relevance used?
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.

Please Log in to join the conversation.

More
2 years 11 months ago #114718 by garf
garf replied the topic: Strange behaviour when $('#movenextbtn').click() and relevance used?

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

Please Log in to join the conversation.

More
2 years 11 months ago #114719 by tpartner
tpartner replied the topic: Strange behaviour when $('#movenextbtn').click() and relevance used?
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

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now