Saving respondent's paradata

More
2 years 9 months ago #116809 by eloner
eloner created the topic: Saving respondent's paradata
Hello!
I am using LS since 2012 and it is working fine for my purposes!
I need to save some paradata about the respondent's device (cookies enabled, browser name, engine) in the answers file.
To do this I created a question (Q10, type: equation):

File Attachment:

File Name: limesurvey...2524.lsq
File Size:2 KB



I added the following code to the question:

<p id="device">
</p>
<script>
document.getElementById("device").innerHTML =
"Cookies Enabled is: " + navigator.cookieEnabled
+ "; Browser name is: " + navigator.appName
+ "; Browser code name is: " + navigator.appCodeName
+ "; Engine: " + navigator.product
</script>

In the preview I can see the data I am requesting:

My problem is that the data should be stored in the answers, but it doesn't work.
(I also need to hide the question, but this is the second step of my problem).
What is wrong in my text? Maybe something in the code (I am not expert of Javascript :( !)?
I am using LS Version 2.05+ Build 141229.
Any suggestion would be appreciated!!!!
Thanks
elo
Attachments:

Please Log in to join the conversation.

More
2 years 9 months ago #116817 by tpartner
tpartner replied the topic: Saving respondent's paradata
Place the following script into a short-text question. It will hide that question and load your data.
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Hide this question
		thisQuestion.hide();
 
		// Load the text input
		$('input.text', thisQuestion).val("Cookies Enabled is: " + navigator.cookieEnabled + "; Browser name is: " + navigator.appName + "; Browser code name is: " + navigator.appCodeName + "; Engine: " + navigator.product);
    });	
</script>

Or better, this in the source of a multiple-short-text with 3 sub-questions:
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Hide this question
		thisQuestion.hide();
 
		// Load the text input
		$('input.text:eq(0)', thisQuestion).val(navigator.cookieEnabled);
		$('input.text:eq(1)', thisQuestion).val(navigator.appName);
		$('input.text:eq(2)', thisQuestion).val(navigator.product);
    });	
</script>

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: eloner

Please Log in to join the conversation.

More
2 years 9 months ago #116823 by eloner
eloner replied the topic: Saving respondent's paradata
Wow!!!!
It works perfectly!
Thank you Tony for your precious help!!!!
Elo

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!