0 votes
in SoSci Survey (English) by s002793 (415 points)
edited by s002793

I get the above mentioned error (The variable IN01_02 has not been asked on a previous page during this interview.) sometimes when running my code.

The section where this variable is used is below - its part of a larger code, but everything else is working, only the storage of 1 or 0 fails.

        // Function to show answer (if question is not displayed i.e. has been activated by keypress)
function showanswer() {
	if(frage.style.display == "none") {
		answer.style.display = "";
		document.getElementById("IN01_02").value = "1";  //1 is cheating
		}
  else {
             document.getElementById("IN01_02").value = "0";
           }
}




// Initialization of forwarding
SoSciTools.attachEvent(window, "load", function(evt) {
  window.setTimeout(showanswer, 3500);
});

The error is strange for two reasons:

1) The variable IN01 is definitely in the questionnaire, and variable IN01_01 works fine saving

2) The error does not show up in any (to me) predictable manner:

Sometimes, IN01_02 storage works and it does it correctly (putting a 0 or 1), and sometimes, it shows up in the debug with IN01_02=?? which is when I receive the error.

Most of the time, when I close the questionnaire, reopen it, and start debug testing, it works the first time; when I try it again, the second time, I receive the error. Here's the strangest part: when I try to use javascript console (opening it in Firefox), the error does no longer occur at all; IN01_02 stores the values correctly every time.

Some help would be really great, thanks a lot.

//update: changed the code to include the timer

by SoSci Survey (327k points)
Before I go into detail: Could you please confirm that this error is not cause by Top 1 in this list: https://www.soscisurvey.de/help/doku.php/en:create:filter-solving

Please also make sure that you put JavaScript (what you have posted as code above) into HTML code, and PHP code into PHP code.

The error message is caused by PHP code. Please add this PHP code to your question for further analysis.

1 Answer

+1 vote
by s002793 (415 points)
selected by s002793
 
Best answer

I managed to figure out the problem, it was not error nr 1 :)

The issue is that the function showanswer is only called after a few seconds, due to the event function below - in the case where a participant completes the rest of the page before those seconds are over, the variable IN01_02 would have no content and that is what sends me the error.

Ergo, the perception of the randomness of the error came from the fact that I did not understand that timing had anything to do with it :)

The solution is to delete the variable input from the else section and write 0 into the variable independently of the function showanswer:

// Function to show answer (ONLY if question is not displayed (i.e. has been activated by keypress)
function showanswer() {
	if(frage.style.display == "none") {
		answer.style.display = "";
		document.getElementById("IN01_02").value = "1";  //1 is cheating
		}
}

document.getElementById("IN01_02").value = "0";


// Initialization of forwarding
SoSciTools.attachEvent(window, "load", function(evt) {
  window.setTimeout(showanswer, 3500);
});

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...