Welcome to the LimeSurvey Community Forum

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

javascript not working in limesurvey

More
7 years 9 months ago #138639 by Dam
I am trying to make a timer and i have coded for that part and it is working But when I am using this code in limeSurvey then it is not working. I have changed the Global setting for Html filter for XSS to No. Still code is not working.
Can anyone help in this?

code of timer that is added in scripts/template.js is :

function startTimer(duration, display) {
var start = Date.now(),
diff;
function timer() {
// get the number of seconds that have elapsed since
// startTimer() was called
diff = duration - (((Date.now() - start) / 1000) | 0);

// does the same job as parseInt truncates the float
minutes = (diff / 60) | 0;
seconds = (diff % 60) | 0;

minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;

display.textContent = minutes + ":" + seconds ;

if (diff <= 0) {
// add one second so that the count down starts at the full duration
// example 05:00 not 04:59
//start = Date.now() + 1000;
clearInterval(handle);
display.textContent ="Time finished ";
alert("Time is over.Click ok to submit Exam.");
$("#movesubmitbtn").click();
alert("vitually clicked submit");
}
}
// we don't want to wait a full second before the timer starts
timer();
handle = setInterval(timer, 1000);

}

function setCookie(cname,cvalue) {
document.cookie = cname+"="+cvalue;
}

function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca;
while (c.charAt(0)==' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return "";
}

window.onload = function(){
alert( "time is"+{GROUPDESCRIPTION} );
var examTime;
var display = document.querySelector('#time');

if(getCookie("examDuration")=== ""){
//cookie is not defined
setCookie("examDuration", 60*5);
examTime=getCookie("examDuration");
} else{

examTime=getCookie("examDuration");
}
startTimer(examTime, display);
$("#movenextbtn").click(function(){
var remainingTime = (parseInt(minutes,10) * 60) + parseInt(seconds,10) ;
setCookie("examDuration", remainingTime);
alert("next btn is clicked, examTime : "+examTime +" and remainingTime : "+remainingTime);
clearInterval(handle);
location.reload();
});
$("#movesubmitbtn").click(function(){
var remainingTime = (parseInt(minutes,10) * 60) + parseInt(seconds,10) ;
setCookie("examDuration", remainingTime);
clearInterval(handle);
alert("submit btn is clicked and remaining time :" + remainingTime);
});

code added in Startgroup.tsptl is :
<p>Time left <br> <span id="time" ></span></p>

one library link is added:
<script src=" ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js ">

I don't know why it is not working in limesurvey and working when i run it utside limesurvey. Any help will be welcomed. Thanks in advance.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 9 months ago #138647 by tpartner
Replied by tpartner on topic javascript not working in limesurvey
There are several JavaScript errors. Use a developers tool in Chrome or Firebug for Firefox to debug them.

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: Dam
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 9 months ago #138669 by DenisChenu
Replied by DenisChenu on topic javascript not working in limesurvey
And LS already include jquert : the remove your inclusion.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
More
7 years 9 months ago #138776 by Dam
Replied by Dam on topic javascript not working in limesurvey
Thanks for reply. I have added Image of errors shown by developer tool. how i correct these errors.
Attachments:
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 9 months ago #138786 by DenisChenu
Replied by DenisChenu on topic javascript not working in limesurvey
admin_core.js in public page ?

What is your limesurvey version ? Do you have external plugin activated ?

Denis

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
More
7 years 9 months ago #138796 by Dam
Replied by Dam on topic javascript not working in limesurvey
It is a latest version and what do u mean by external plugin?
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 9 months ago #138819 by holch
Replied by holch on topic javascript not working in limesurvey
The question is what do you mean with "a latest version"? Why not giving the built number, then it is clearer.

And Denis asks if you have some plugin installed that doesn't come with the limesurvey core.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 9 months ago #138823 by DenisChenu
Replied by DenisChenu on topic javascript not working in limesurvey
The nscreenshot seems to be with template editor : tempalte editor is noit real survey.

Test with a real survey

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
More
7 years 9 months ago #138859 by Dam
Replied by Dam on topic javascript not working in limesurvey
Thanks for reply. @DenisChenu yes it is with template editor but i have tested it with real survey also.
@holch limesurvey that we are using was released in april. and that should be 1.9+ and i don't know build number of that. Is this is working in any of your test in lime survey?

thanks once again
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 9 months ago #138860 by DenisChenu
Replied by DenisChenu on topic javascript not working in limesurvey
Hi,

1 : Then : show the test in public template ...
2 : Build number it at end of the page when you are connected to admin
3 : "Is this is working in any of your test in lime survey?" when i make a javascript : it always work on limesurvey. But here : you don't give me the key to debug your script ... Send a public link test for example.

We can help if user help us to help ...

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
More
7 years 9 months ago #138867 by Dam
Replied by Dam on topic javascript not working in limesurvey
Hi,
Thank for reply. @DenisChenu I am using lime survey version 2.50+Build 160413. In plugin section i found that limesurvey Internal database is deactivated. I don't know about it what it will do.
I am testing it in localhost so I can't provide link today. Once i will make these changes on our server then i will send a link tomorrow to u. But I have attached two image here one of first page and anther of question section in which timer should be shown but it is not picking.



The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 9 months ago - 7 years 9 months ago #138870 by DenisChenu
Replied by DenisChenu on topic javascript not working in limesurvey
You can use limeservice to do such test , more quick and always available.

Just remind to
- allow xss
- allow preview without admin rights

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 7 years 9 months ago by DenisChenu.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose