Check out the LimeSurvey source code on GitHub!

record prefill answer to hidden question

More
5 years 10 months ago - 5 years 10 months ago #59451 by ftrifoglio
I would use javascript to prefill a short free text question, let's say with a random number.

$(document).ready(function() {
var randNumber = Math.floor(Math.random()*9999999999999 + 1);
$('input#answer{SGQ}').val(randNumber);
});
</script>

Then I would hide the question and record the value/answer.

Finally I would display the value to the user with a boilerplate question with the SGQA identifier.

It works if I don't hide the question.
How can I record the answer of a hidden question?
Last Edit: 5 years 10 months ago by ftrifoglio.

Please Log in to join the conversation.

More
5 years 10 months ago - 5 years 10 months ago #59472 by tpartner
If you want to use JavaScript, you cannot hide the question with the "Always hide this question" setting. That setting prevents the question from being loaded into the DOM (I see no use for that setting).

Hide the question with CSS:
#question11 {
	display: none;
}

Or JavaScript:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		$('#question11').hide();
	});
 
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 5 years 10 months ago by tpartner.

Please Log in to join the conversation.

More
5 years 10 months ago - 5 years 10 months ago #59484 by ftrifoglio
It is the solution for a group-by-group survey.

In a question-by-question, the user would see just a blank page with the next button, and maybe he waits that something happen.

Then I would add a function to automate the form submission.

document.limesurvey.submit();

Do you think this may cause any problem?
Last Edit: 5 years 10 months ago by ftrifoglio.

Please Log in to join the conversation.

More
5 years 10 months ago #59490 by tpartner
Ah, yes, the solution is for a group-by-group survey. By necessity, almost all workarounds using hidden questions are for group-by-group.

You can auto-submit the page but that may lead to problems with people trying to go back in the survey.

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.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form