- Posts: 3
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Add data to csv file
- L1m3ss
- Topic Author
- Offline
- New Member
Less
More
3 years 6 months ago #208036
by L1m3ss
Add data to csv file was created by L1m3ss
Hi,
I have added the html code for a question myself, however it isn't displayed properly in the exported csv file. To be more specific, I am displaying numbers in a table which will be randomised whenever the page is refreshed/accessed by a different user (see code). I would like to store the numbers the current user sees in the csv file. This would mean I would have an extra column for each factor. Each value of the factor is displayed as a row.
Does anybody know how I can do this?
Here is the code of the question text:
<table>
<tbody>
<tr>
<th>
Factor</th>
<th>
Value</th>
</tr>
<tr>
<td>
Street lighting</td>
<td>
<p id="Lighting">
</p>
<script>
function getRandomArbitrary(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
document.getElementById("Lighting").innerHTML = getRandomArbitrary(1, 5);
</script></td>
</tr>
<tr>
<td>
Density</td>
<td>
<p id="Density">
</p>
<script>
function getRandomArbitrary(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
document.getElementById("Density").innerHTML = getRandomArbitrary(1, 5);
</script></td>
</tr>
</tbody>
</table>
Many thanks!
I have added the html code for a question myself, however it isn't displayed properly in the exported csv file. To be more specific, I am displaying numbers in a table which will be randomised whenever the page is refreshed/accessed by a different user (see code). I would like to store the numbers the current user sees in the csv file. This would mean I would have an extra column for each factor. Each value of the factor is displayed as a row.
Does anybody know how I can do this?
Here is the code of the question text:
<table>
<tbody>
<tr>
<th>
Factor</th>
<th>
Value</th>
</tr>
<tr>
<td>
Street lighting</td>
<td>
<p id="Lighting">
</p>
<script>
function getRandomArbitrary(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
document.getElementById("Lighting").innerHTML = getRandomArbitrary(1, 5);
</script></td>
</tr>
<tr>
<td>
Density</td>
<td>
<p id="Density">
</p>
<script>
function getRandomArbitrary(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
document.getElementById("Density").innerHTML = getRandomArbitrary(1, 5);
</script></td>
</tr>
</tbody>
</table>
Many thanks!
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10121
- Thank you received: 3599
3 years 6 months ago #208040
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Add data to csv file
You will need to store the value in a hidden question or input. The details depend on the survey structure and question types.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13053
- Thank you received: 4020
3 years 6 months ago #208042
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Add data to csv file
You should use two equations to define the two values
like
eq1: {if(is_empty(eq1),rand(1,5),eq1)}
eq2: {if(is_empty(eq1),rand(1,5),eq2)}
And in your question text
So you will find the values in the csv-file
"id","submitdate","lastpage","startlanguage","seed","eq1","eq2","boilerplate1"
"2","1980-01-01 00:00:00","2","en","583167754","5","3",""
Joffm
like
eq1: {if(is_empty(eq1),rand(1,5),eq1)}
eq2: {if(is_empty(eq1),rand(1,5),eq2)}
And in your question text
Code:
<table> <tbody> <tr> <th>Factor</th> <th>Value</th> </tr> <tr> <td>Street lighting</td> <td>{eq1}</td> </tr> <tr> <td>Density</td> <td>{eq2}</td> </tr> </tbody> </table>
So you will find the values in the csv-file
"id","submitdate","lastpage","startlanguage","seed","eq1","eq2","boilerplate1"
"2","1980-01-01 00:00:00","2","en","583167754","5","3",""
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
- L1m3ss
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
3 years 6 months ago #208073
by L1m3ss
Replied by L1m3ss on topic Add data to csv file
Thank you so much for your help! I did not know this was possible and I am very glad it is:)
The topic has been locked.
- L1m3ss
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
3 years 6 months ago #208074
by L1m3ss
Replied by L1m3ss on topic Add data to csv file
Thank you tpartner for such a quick response. Together with Joffm's reply, I got it to work.
The topic has been locked.