https://www.qualtrics.com/community/discussion/comment/29313#Comment_29313I assume that my solution is overkill since I am sure there is a way to actually clear the interval like has been suggested, I just never could figure it out.What I ended up doing was adding this code to the first question on each page: Qualtrics.SurveyEngine.addOnPageSubmit(function() { Qualtrics.SurveyEngine.setEmbeddedData('timeRemaining',timer); clearInterval(myTimer); // fairly certain this isn't doing anything }); Qualtrics.SurveyEngine.addOnUnload(function() { document.getElementById("header_container").remove(); });This takes the time left on the timer when the participant clicks the button to go to the next page and saves it as embedded data into Qualtrics. After that, my goal was to remove the entire timer object from the page, I’m not sure if that is what the code explicitly does but it worked for me. Then on the first question of the next page, the timer gets built but instead of reading in the
I believe I understand what you mean for the alternative solution but I don't really know enough about java and programming to do that. The code I'm using is mostly copied and I don't really understand how to make the time formatting into it's own function, or even where in the above code I would put that function. I get the basic concept but I've tried a few dozen different things since you replied and none of them have worked. Could you give me some tips as to what I would need to do to isolate the formatting as it's own function?I appreciate the help, assuming this also resolves the timer being delayed by 1 second when a page loads this should be the last problem I need to solve for this survey.
Thanks for the fast reply, I think my inexperience is really showing because the code you mention doesn’t work for me. I added it at the very end of the addOnload function and nothing happens to the timer when it loads the next page. For clarity, the entire JavaScript I have attached to the question on the first page is:Qualtrics.SurveyEngine.addOnload(function(){var headerCont = document.createElement("div"); headerCont.className = "header-cont"; headerCont.id = "header_container"; var header = document.createElement("div"); header.className = "header" header.id = "header_1"; var timer = document.createElement("div"); timer.className = "timer"; timer.id = "timer_1"; timer.innerHTML = "Time Remaining: 07:30"; // set actual time limit correctly hereheaderCont.appendChild(header); header.appendChild(timer); document.body.insertBefore(headerCont, document.body.firstChild); function sta
Thanks again for the continued help. As a complete newbie to JavaScript (and coding in general) I am not sure how to go about clearing the interval on each page as you say. I understand that currently the code if (--timer < 0) { clearInterval(myTimer); timeOver();}is what you are referring to when you say it keeps going. My guess at a solution would be to add another if statement that executes when the participant clicks the next page button, and would write the current timer value into embedded data and then call clearInterval again on the timer. Then on each subsequent page, copy over the script that controls the timer and change it slightly so that instead of restarting the timer at whatever starting value it is set to, have it start at whatever value is stored in the embedded data. If these assumptions are correct, my problem is I don’t know what the syntax is to have code execute upon clicking the next page button. My guess at how to write the if statement curren
I appreciate the response, I had seen that post prior to posting but being new to this whole system means I don’t fully understand it. I have managed to find out how to get the survey to auto advance to the place I want upon the timer reaching 0 by looking through these forums more thoroughly, although I am sure my solution isn’t very efficient or elegant (discussed below in case it could help anyone else.) However, I am still unclear on clearing the timer from the top of the screen. The blog post I initially took this code from mentioned the distinction between static and dynamic themes possibly causing problems but it is outdated and I’m not getting the problem it describes. Currently, all of my Javascript is loaded on the first question of the block where I want the timer to appear, and that is it. Using dynamic or static themes doesn’t cause any problem but the timer persists after the block ends. The post you linked to mentions clearing the interval upon leaving the page and then
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
Sorry, we're still checking this file's contents to make sure it's safe to download. Please try again in a few minutes.
Sorry, our virus scanner detected that this file isn't safe to download.