Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Extracting code to conditions with if/else

  • NECS_labo
  • NECS_labo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 10 months ago #217617 by NECS_labo
Hi,

In my questionnaire, I created a code to randomly assign participants to one of my two conditions with an if/else code. However when I extract my data, I have no idea in which condition the participant was assigned since I see the text to both my conditions. Do you have any clue on how to fix this ?

Thank you,
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago #217624 by holch
Replied by holch on topic Extracting code to conditions with if/else
Not sure how you used conditions in this case. Are you talking about expressions?

Could you upload a small prototype LSS of what you did? Just the relevant questions? Because I am currently not sure what you actually did and how.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • NECS_labo
  • NECS_labo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 10 months ago #217641 by NECS_labo
Replied by NECS_labo on topic Extracting code to conditions with if/else
Here's my code.

<div id="d4" style="text-align: center;"><span style="font-size:22px;"><span style="font-family:Arial,Helvetica,sans-serif;"><span style="background-color:#ffffff;">Three other participants said it is appropriate.</span></span></span></div>

<div style="text-align: center;"> </div>

<div id="d5" style="text-align: center;"><span style="font-size:22px;"><span style="font-family:Arial,Helvetica,sans-serif;"><span style="background-color:#ffffff;">Three other participants said it is inappropriate.</span></span></span></div>

<div style="text-align: center;"> </div>

<div id="d1" style="text-align: center;"><span style="font-size:22px;"><span style="font-family:Arial,Helvetica,sans-serif;"><span style="background-color:#ffffff;">Jacob is on the city sidewalk cycling.</span></span></span></div>

<div style="text-align: center;"> </div>

<div id="d3" style="text-align: center;"><font face="Arial, Helvetica, sans-serif"><span style="font-size: 18px;">The scenario is...</span></font></div>

<div style="text-align: center;"> </div>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
var rand = Math.random(); // generates an int of 0 or 1
if (rand < 0.5){
$('#ls-button-submit').hide();
$("#d2").hide();
$("#d3").hide();
$(".answer-container").hide()
$("#d4").show();
$("#d1").hide();
$("#d5").hide();
setTimeout(function () {
$('#d1').show();
$('#d4').show();
}, 3000);
setTimeout(function () {
$('#d1').hide();
$('#d2').show();
$('#d3').show();
$('#d4').show();
$(".answer-container").show();
$('#ls-button-submit').show();
return("appropriate");

}, 8000);
} else {
$('#ls-button-submit').hide();
$("#d2").hide();
$("#d3").hide();
$(".answer-container").hide()
$("#d5").show();
$("#d4").hide();
$("#d1").hide();
setTimeout(function () {
$('#d1').show();
$('#d5').show();
}, 3000);
setTimeout(function () {
$('#d1').hide();
$('#d2').show();
$('#d3').show();
$('#d5').show();
$(".answer-container").show();
$('#ls-button-submit').show();
return("inappropriate");

}, 8000);
}
});

</script><script type="text/javascript" charset="utf-8">

$(document).on('ready pjax:scriptcomplete',function(){

if($.trim($('#question{QID} textarea:eq(0)').val()) == '') {
$('#question{QID} textarea:eq(0)').val(new Date());
}
$('#question{QID} .answers-list').removeClass('col-sm-6');
$('#question{QID} .text-item').hide();
});
</script>

But when I extract my data, I can see the text to both my conditions, so there's no way of knowing in which condition the participant was placed in.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago #217643 by tpartner
Replied by tpartner on topic Extracting code to conditions with if/else
I don't see anywhere that you have loaded the "appropriate/inappropriate" values into a LimeSurvey question. All I see is a date value loaded into a long-text question.

Can you attach a survey export (.lss file) as holch asked?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • NECS_labo
  • NECS_labo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 10 months ago #217651 by NECS_labo
Replied by NECS_labo on topic Extracting code to conditions with if/else
 
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago #217653 by holch
Replied by holch on topic Extracting code to conditions with if/else
I not sure why you are uploading a screenshot of an Excel sheet.

We want to see a LSS export, so we can import it and see what you have actually done to randomly assign the participants. Only this way we can check if there is a way to get to the information you want or not.

You already said that you can't see it in the export, so showing that again doesn't really help. We need to know what you did in your survey to assign respondents randomly and understand what you did.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • NECS_labo
  • NECS_labo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 10 months ago #217656 by NECS_labo
Replied by NECS_labo on topic Extracting code to conditions with if/else
Oh, sorry I am new to LimeSurvey.

Here's the .lss file. It is the SC question group that is not working. 

File Attachment:

File Name: limesurvey...7317.lss
File Size:529 KB
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago #217701 by holch
Replied by holch on topic Extracting code to conditions with if/else
This is a monster of a survey with many questions.

Please explain what you are doing in which question and what you are trying to achieve. In the SC group there are 61 questions.

What about these questions? What does not work?

What I don't get is for example why the question "cosnigne" is a Long free text (Type: T), why not a text display? Are respondents supposed to write something into the text field?

Anyway, I had a quick look at one or two questions in this question group and what you are doing is showing randomly, via Javascript, some statements that people are supposed to rate as appropriate or inappropriate. That seems to work fine. Limesurvey seems to do exactly what you are asking it to do via Javascript.

But of course you won't know what version of your question has been shown, because you are doing all this with Javascript in the question text but you don't seem to save the result of your randomization anywhere. As soon as the respondent moves to the next question, the information is of course gone, if you do not write it to the database somewhere.

I would probably create the "condition" in an Equation type question and then draw it from there. Or draw via Javascript, but then write the result of the randomization into a hidden (via CSS) equation question to store it.

The way you do it, I am not surprised that you won't find the information about the randomly picked scenario in your exported data.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose