Welcome to the LimeSurvey Community Forum

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

Create a Quota question and punch that by using answer of the previous question

More
9 years 2 months ago #124409 by Ni3
Hi,

I want to create a hidden question with a single response type for quota, this question will have 4 stubs/responses and punch them by using the previous question (multiple responses need to consider while punching the quota question).
I believe this can be done by using the JavaScript. Could you please share the example/code if anyone has done this earlier.

Thank you!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 2 months ago #124418 by tpartner
Sorry, I can't figure out your requirements. Are all questions on the same page. Can you be more clear on what the question types are and what the expected behaviour is?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
9 years 2 months ago #124423 by Ni3
Hi tpartner,

Here is the example.
Q1. “How familiar are you with this product type?” (radio button)
1) Extremely familiar
2) Very familiar
3) Moderately familiar
4) Slightly familiar
5) Not at all familiar

Now I want a quota to classify respondents in to “user” or “non-user”. To achieve this I want to create a hidden question with user and non-user (single response/radio button) as a response stubs. I want to punch this question based on the answer given at Q1.
Hiddenquestion “Quota”
1. User
2. Non-user
If Q1 ==”1” or Q1 ==”2” or Q1 ==”3” then
hiddenquestion = “user”
else
hiddenquestion = “nonuser”
end if
If required I will keep these two questions on same page.
Please let me know if this is not clear.
The topic has been locked.
More
9 years 2 months ago #124425 by jelo
You can set a hidden e.g yes/no question via a equation question.
The hidden yesno question is called yesno.
The equation to set yes or no would follow this format:
{yesno=if(screenoutS01.NAOK>0,"Y","N")}
screenoutS01.NAOK>0 needs to be replaced with your stuff.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
More
9 years 2 months ago #124446 by Ni3
Thank you for your response, jelo.
But I believe quota does not Supported the equation question. I want to use that hidden question in the quota.
The topic has been locked.
More
9 years 2 months ago #124448 by jelo
The equation is used to set the answer of the yesno-question. The yesno-question is used in the quota, not the equation question.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 2 months ago #124449 by tpartner
Assuming the following...

- Both questions are on the same page and the quota question directly follows Q1
- The answer codes for Q1 are 1, 2, 3, 4, 5

...you can use JavaScript to hide the quota question and toggle it depending on radios clicked in Q1.

Set up your survey to use JavaScript and place this script in the source of Q1:

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function() {  
 
    // Identify the questions
    var thisQuestion = $('#question{QID}');
    var qHidden = thisQuestion.nextAll('.list-radio:eq(0)');
 
    // Hide qHidden
    qHidden.hide();
 
    // Listener on the Q1 radios
    $('input.radio', thisQuestion).on('click', function(e) {
      if($(this).attr('value') < 4) {
        $('input.radio:eq(0)', qHidden).trigger('click');
      }
      else {
        $('input.radio:eq(1)', qHidden).trigger('click');
      }
    });
    });
</script>

For testing, you can comment out this line:
Code:
qHidden.hide();

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
9 years 2 months ago #124450 by jelo
I am not sure if this issue is caused by the javascript workaround or because it was used it in connection with token attributes.
The problem was, that quota check was applied to all respondents during the interview. And not at the position, where the hidden question was. That caused all respondents to be kicked out during the interviews, when the quota was filled. Which shouldn't happen.

www.limesurvey.org/en/forum/can-i-do-thi...elds?start=10#123979

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 2 months ago #124452 by tpartner

I am not sure if this issue is caused by the javascript workaround...

Is this in reference to the solution I just presented? If so, did you test?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
9 years 2 months ago #124454 by jelo
I haven't tested your solution. I wanted to point out, that there might be a problem with quotas set via Javascript when quota gets full. I could reproduce that problem in connection with token attributes, which were set via this code:
Code:
<script>
$(document).ready(function()
  {
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Hide this question
    $(thisQuestion).hide();
 
$(function() { $("#question{QID} input.radio[value='{TOKEN:ATTRIBUTE_1}']").click(); });
  });

It worked at intended, but when the quota gets full, Limesurvey will not only block new probands entering the survey, but also all probands which already passend the quota before it where full. Since this workaround was presented more than once for creating quotas for questionstypes not supported, I wanted to point out a possible issue.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 2 months ago #124458 by tpartner
Well, this post says nothing about tokens and I have no idea what the problem is with your survey or code but I did test my solution and it does work!

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
9 years 2 months ago #124462 by jelo

tpartner wrote: Well, this post says nothing about tokens and I have no idea what the problem is with your survey or code but I did test my solution and it does work!

It seems you really didn't get what I meant. Did you test your workaround with more one proband filling out the survey at the same time?
That is the case I am talking about. When one proband hit the quota, all other users which already passed the quotacheck where screened out too. And since I used a quota question, which was filled out via javascript, I have added a remark about a possible issue around this kind of workaround. Since I can't rule out, that it only happens in connection with tokens attributes, I mentioned that too. Nothing more, nothing less. This happened on 2.05+ 20150608. Since 2.06+ is broken, I don't use that beside for debugging tests.
The threadstarter will see, if the issue applies here too. When one or more probands will be kicked out of the survey in the middle or the end of the survey which a screen "Quota full".

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose