Welcome to the LimeSurvey Community Forum

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

javascript not working in limesurvey

More
9 years 1 month 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.
More
9 years 1 month ago #138647 by tpartner
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.
More
9 years 1 month ago #138669 by DenisChenu
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 support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
More
9 years 1 month ago #138776 by Dam
Thanks for reply. I have added Image of errors shown by developer tool. how i correct these errors.
The topic has been locked.
More
9 years 1 month ago #138786 by DenisChenu
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 support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
More
9 years 1 month ago #138796 by Dam
It is a latest version and what do u mean by external plugin?
The topic has been locked.
More
9 years 1 month ago #138819 by holch
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.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The topic has been locked.
More
9 years 1 month ago #138823 by DenisChenu
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 support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
More
9 years 1 month ago #138859 by Dam
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.
More
9 years 1 month ago #138860 by DenisChenu
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 support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
More
9 years 1 month ago #138867 by Dam
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.
More
9 years 1 month ago - 9 years 1 month ago #138870 by DenisChenu
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 support - Plugins, theme and development .
I don't answer to private message.
Last edit: 9 years 1 month ago by DenisChenu.
The topic has been locked.
More
9 years 1 month ago #139004 by Dam
Thanks for reply @DenisChenu, @holch @tpartner.
Here is the link of the test which i generated using lime suevey.
https://192.168.1.11/limesurvey/index.php/198?lang=en&examTime=45

the Template I am using is attached below in response.
one more thing is in attachment an that is file containing program of only timer which is running good individually but not in limesurvey.
this is the all content I have used in this.
I have allowed XSS when I started adding javascript to limesurvey .

If u need anything else to correct it mention that in reply. I am frustrated because i am unable to find the solution of this problem in more than 3 weeks time span.

Thanks in advance for help you will do. My all hopes are on your shoulder.
More
9 years 1 month ago #139023 by tpartner
1) The link to your test is on your local server and not available to us on the internet.

2) I see no sample survey export file (.lss file) in your attachments so we have no way of testing.

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: DenisChenu
The topic has been locked.
More
9 years 1 month ago #139068 by Dam
Thanks for reply @tpartner

I thought that link may work for you as that link was working in my phone and other system than localhost. It will need one day time to upload the file to server and create a exam as i don't have credential of that.
I hope that you have got two zip file one was template that i used and other is program of timer . U can use javascript part of that template whether it is error-less or not.

U can use that code of timer in test generated by you in limesurvey.

I will provide the link of test tomorrow that will work on internet.

this reply have one file that is of survey in lss format.May help you guys.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose