Applying a quota to a free text or numerical question

LimeSurvey does not allow you to apply a quota to a text based question or a numerical question out of the box. This can be a pain when you have questions that require specific numerical answers (such as a persons age), but you then want to set quotas based on numerical ranges.

To do it with LimeSurvey’s standard quota feature you would have to present your participants with a List type question – and ask them to select an age group (or alternatively give every possible age from 1 to 120 in a radio list). Asking your participants for their specific age, and then following it up asking them to select which age range applies to them is unweildy and likely to annoy them – that last thing you want to do.

But with a little bit of jQuery you can ask your users for their age, then – in the background out of their site – fill in a list question so you can apply a quota to it.

Here’s how.

Firstly you need to have your two questions set up. The first question should ask the participants for their age. The subsequent question should be a list question with your age ranges – such as:

* 0 – 18
* 19 – 24
* 25 – 34
* 35 – 44
* 45 – 54
* 55 – 64
* 65 and over

For this particular solution, ensure the questions are in different pages. If your survey is question-by-question that’s already done, but if you’re presenting group-by-group, make sure they’re not in the same group. This solution won’t work in an “All-in-one” survey.

Gather the SGQA information for your two questions. Let’s say your first question – the numerical question asking the respondents age – is 999999X122X554, and your list question – containing the age ranges – has an SGQA of “999999X123X555” and you’ve called your age groups, respectively, A to G

In the help field of the second question insert the following code:

<script type='text/javascript'>
$(document).ready(function() {
  /* This gets the age that was entered in the numerical question */
 var age="{INSERTANS:999999X122X554}"; /* Change this to match your numerical question SGQ */

  var updateName='#answer999999X123X555'; /* Change this to match your list question SGQ */
  var updateCode='';
  if(age < 19) {
  } else if (age > 18  && age < 25) {
  } else if (age > 24  && age < 35) {
  } else if (age > 34  && age < 45) {
  } else if (age > 44  && age < 55) {
  } else if (age > 54  && age < 65) {
  } else if (age > 65) {
  $(updateName+updateCode).attr("checked","checked"); /* First we "check" the radio button */
  $(updateName+updateCode).click();  /* Then we fake the mouse click, to fire off any conditions in LimeSurvey */
  $(updateName+updateCode).change(); /* Then we fake the change, to also make sure any conditions are applied */
  $('div.#question555').hide(); /* And we hide the list question so the participant can't see it */

Hope this is useful!