Welcome, Guest
Username: Password: Remember me

TOPIC: record prefill answer to hidden question

record prefill answer to hidden question 3 years 3 months ago #59451

  • ftrifoglio
  • ftrifoglio's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 20
  • Karma: 1
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: 3 years 3 months ago by ftrifoglio.
The administrator has disabled public write access.

Re: record prefill answer to hidden question 3 years 3 months ago #59472

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 747
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 3 years 3 months ago by tpartner.
The administrator has disabled public write access.

Re: record prefill answer to hidden question 3 years 3 months ago #59484

  • ftrifoglio
  • ftrifoglio's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 20
  • Karma: 1
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: 3 years 3 months ago by ftrifoglio.
The administrator has disabled public write access.

Re: record prefill answer to hidden question 3 years 3 months ago #59490

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 747
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.151 seconds
Donation Image