Workarounds: Manipulating a survey at runtime using Javascript
These workarounds were shared by LimeSurvey users. They are not official LimeSurvey features, and LimeSurvey can't give support for them. If you have questions, ask in the LimeSurvey forum.
Many tasks that used to need a workaround are built-in settings now. See Workarounds first.
{ and before every }, or ExpressionScript reads the code as an expression. {QID} is replaced with the ID of the question the script is in.On the Free plan, survey sites created from January 2026 can't use JavaScript in question texts. See The free plan.
Replaced by built-in features
These workarounds are no longer needed:
| Workaround | Use now |
|---|---|
| Add up answers or show a running total | An Equation question with sum(). For a multiple numerical input question, see QS:Equals num value, QS:Min num value and QS:Max num value.
|
| Check answers across several questions, make single rows of an array mandatory, require a minimum number of characters | Question validation equation and Subquestion validation equation. See Validation: make sure the answers you get are usable. |
| Check the format of a phone number or email address | Input validation with a regular expression. See QS:Preg validation and Validation: make sure the answers you get are usable. |
| Send participants to another page depending on an answer | A quota with the action Terminate survey and a URL (see Quotas), or an end URL with an expression (see URL fields). |
| Run your own code when the page is loaded or an answer changes | See JavaScript in questions and JavaScript examples you can copy. In a multilingual survey, add the script to the question text of every language. |
| Show only the options someone chose in an earlier question | Array filter. See QS:Array filter and QS:Array filter exclude. |
| Filter the columns of an Array by column question | Use an Array question with the items as rows and Array filter (see QS:Array filter). Array by column has no array filter. |
| Show options or array rows only when an earlier option is chosen or a row is answered | A relevance equation on the subquestion, for example !is_empty(Q1_SQ001). See Adding answers or subquestions.
|
| Prefill a question with an earlier answer | Default answers with an expression. See Default answers. |
| Make participants stay a minimum time on a page | Navigation delay (seconds) in the presentation settings of the survey. See Presentation. For one question, see QS:Time limit. |
| Randomize answers or subquestions but keep some at a fixed place | Keep codes at original positions together with Random order. See QS:Keep codes order and QS:Random order. |
| Show one of several pictures or videos at random and record which one | An Equation question with rand() stores a random number. Give each picture or video a text display question with a relevance equation on that number.
|
| Personal limits for a multiple numerical input | Enter an expression, for example {TOKEN:ATTRIBUTE_1}, in Maximum sum value. See QS:Max num value.
|
| Record how long participants spend on a page | Save timings. See Notifications & data and Timing statistics. |
| Hide empty help texts | Nothing to do: Fruity TwentyThree hides empty help texts. |
| Ask for a time | A Date/Time question with a date/time format that has only hours and minutes. See QS:Date time format. |
| Calculate the difference between two dates | An Equation question with strtotime(), for example (strtotime(D2) - strtotime(D1)) / 86400 for days. See ExpressionScript functions.
|
| Limit a date by another date question | Minimum date and Maximum date accept expressions, for example the code of the other date question. See QS:Date min and QS:Date max. |
| Prevent submitting the page with the Enter key | Nothing to do: in Fruity TwentyThree, Enter in a text field moves to the next field and doesn't submit the page. |
| Write the answer in capital letters | See Write the answer in capital letters. |
| Arrays on small screens | Fruity TwentyThree shows arrays in a layout for small screens. To show the answers of an array as dropdowns on all screens, see QS:Use dropdown. |
| Number field with plus and minus buttons, in steps of 0.5 | A Multiple numerical input question with a slider (see QS:Slider layout and QS:Slider accuracy), or a validation equation. See Validation: make sure the answers you get are usable. |
| MaxDiff question | See Create MaxDiff question type. |
| Q sorting: sort statements into columns, with a fixed number of statements per column | An Array question with the statements as subquestions and the columns as answer options, and a Question validation equation with countif() for each column, for example countif('M1', self) <= 1 and countif('N0', self) <= 3 and countif('P1', self) <= 1. See Validation: make sure the answers you get are usable. For drag and drop, see the question theme Card sorting under Question themes from the community.
|
Focus on the first input field
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
This script puts the cursor into the first answer field of each page, so participants can start typing at once.
Add it to custom.js of your theme (see Adding your own CSS and JavaScript) to use it on all pages, or between <script> tags in a question text to use it on one page.
$(document).on('ready pjax:scriptcomplete', function () {
$('#limesurvey .answer-container :input:visible:enabled').first().focus();
});
Answer questions by keypress
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
With this script, participants answer a single choice question with the number keys and go to the next page at once: 1 selects the first answer, 2 the second, and so on; 0 selects the tenth answer. It works for question types with radio buttons, such as List (Radio) and Yes/No. Use it with one question per page.
Add the script to the source of the question text:
<script type="text/javascript">
$(document).on('ready pjax:scriptcomplete', function () {
$(document).off('keypress.answerByKey').on('keypress.answerByKey', function (e) {
// Ignore keys typed into text fields
if ($(e.target).is('input[type="text"], textarea')) { return; }
var key = e.which - 48;
if (key < 0 || key > 9) { return; }
// 1 selects the first answer, 0 the tenth
var index = (key === 0) ? 9 : key - 1;
var radio = $('#question{QID} input[type="radio"]').eq(index);
if (radio.length) {
radio.trigger('click');
$('#ls-button-submit').trigger('click');
}
});
});
</script>
Auto-tabbing between text input fields
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
When a participant has typed the maximum number of characters into a text field, the cursor moves to the next text field on the page.
- Create the text questions, for example short free text questions.
- Set Maximum characters for each question the script should leave automatically. See QS:Maximum chars.
- Add the script to the source of the first question text on the page:
<script type="text/javascript">
$(document).on('ready pjax:scriptcomplete', function () {
var fields = $('#limesurvey .answer-container input[type="text"]:visible');
fields.on('input', function () {
var max = parseInt($(this).attr('maxlength'), 10);
if (max && this.value.length >= max) {
fields.eq(fields.index(this) + 1).focus();
}
});
});
</script>
Text input masks
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
A mask lets participants enter only characters that fit a pattern, for example a phone number in the format (###) ###-####. This example loads the Masked Input plugin from a CDN.
Add the script to the source of the question text of a short free text question:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.min.js"></script>
<script type="text/javascript">
$(document).on('ready pjax:scriptcomplete', function () {
$('#question{QID} input[type="text"]').mask('(999) 999-9999', { placeholder: '_' });
});
</script>
In the mask, 9 stands for a digit, a for a letter and * for a letter or digit. To check the format on the server too, also set Input validation (see QS:Preg validation).
Store a random checked answer of a multiple choice question
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
The script picks one of the options a participant checked in a multiple choice question at random and stores its text in a short free text question. You can then use that answer later in the survey, for example to ask more about one product the participant bought.
- Create a Multiple choice question. An Other option works too: the script stores the text the participant typed.
- Directly after it, create a Short free text question. The script hides it and fills it in. Don't use Always hide this question for it: the question is then not on the page, and the script can't fill it in.
- Add the script to the source of the multiple choice question text:
<script type="text/javascript">
$(document).on('ready pjax:scriptcomplete', function () {
var thisQuestion = $('#question{QID}');
// The short text question right after this question stores the result.
// Hide it with this script, not with "Always hide this question".
var hiddenQuestion = thisQuestion.nextAll('.text-short').first();
var hiddenInput = $('input[type="text"]', hiddenQuestion);
hiddenQuestion.hide();
function pickRandomAnswer() {
var checkedAnswers = [];
$('input[type="checkbox"]:checked', thisQuestion).each(function () {
var item = $(this).closest('.answer-item');
if (item.hasClass('checkbox-text-item')) {
// The "Other" option: use the text the participant typed
checkedAnswers.push($.trim($('input[type="text"]', item).val()));
} else {
checkedAnswers.push($.trim($('label', item).first().text()));
}
});
var value = '';
if (checkedAnswers.length) {
value = checkedAnswers[Math.floor(Math.random() * checkedAnswers.length)];
}
hiddenInput.val(value).trigger('keyup');
}
$('input[type="checkbox"]', thisQuestion).on('change', pickRandomAnswer);
$('input[type="text"]', thisQuestion).on('keyup change', function () {
setTimeout(pickRandomAnswer, 250);
});
});
</script>
Use the stored answer later in the survey, for example with {QH} if the short free text question has the code QH. See Piping: use answers from previous questions.
Variable length array
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
Participants add or remove rows of an Array (Texts) question as they need them. At first only the first row is shown, plus an Add row button. The script also respects relevance equations on the subquestions.
Don't make the question mandatory: participants can't fill in the rows that are hidden.
In the classic editor, add the script to the Script field of the question (no <script> tags needed). Otherwise, add it between <script> tags to the source of the question text:
$(document).on('ready pjax:scriptcomplete', function () {
// A function to add or remove rows of an Array (Multi Flexible)(Text) question
function varLengthArray(qID) {
if ($('#question'+qID+'').length > 0) {
var thisQuestion = $('#question'+qID);
// The HTML content of the Add/Remove elements - modify as you wish
var addContent = '[+] Add row';
var removeContent = '[-] Remove row';
// The classes for the Add/Remove elements - modify as you wish
// See https://getbootstrap.com/docs/5.0/getting-started/introduction/
var addClasses = 'inserted-button add btn btn-success';
var removeClasses = 'inserted-button remove btn btn-danger';
// The styles for the Add/Remove elements - modify as you wish
// These could be placed in your custom.css file.
var addStyles = 'margin:10px 0 10px 10px; padding:1px 5px; text-align:center; width:auto; cursor:pointer; float:left;';
var removeStyles = 'margin:10px 0 10px 10px; padding:1px 5px; text-align:center; width:auto; cursor:pointer; float:left;';
// Insert the buttons
$( 'table.ls-answers', thisQuestion).after('<div class="button-wrapper">\
<button type="button" class="'+addClasses+'" style="'+addStyles+'">'+addContent+'</button>\
<button type="button" class="'+removeClasses+'" style="display: none; '+removeStyles+'">'+removeContent+'</button>\
</div>');
// Listeners on the buttons
$('.inserted-button.add', thisQuestion).on('click', function (event) {
addRow();
});
$('.inserted-button.remove', thisQuestion).on('click', function (event) {
removeRow();
});
// Define the relevant rows
var relevantRows = $('tr.subquestion-list:not(.ls-irrelevant)', thisQuestion);
// Function to add a row, show the "Remove" element and hide the "Add" element if all rows are shown
function addRow() {
$('[data-visible="false"]:first', thisQuestion).attr('data-visible', 'true').show();
$('.inserted-button.remove', thisQuestion).show();
if ($('[data-visible="false"]', thisQuestion).length == 0) {
$('.inserted-button.add', thisQuestion).hide();
}
$('.inserted-button.add', thisQuestion).blur();
}
// Function to remove a row, clear the contents of the removed row,
// show the "Add" element if the last row is hidden and hide the "Remove" element if only the first row is shown
function removeRow() {
$('[data-visible="true"]:last input:text', thisQuestion).val('').trigger('keyup');
$('[data-visible="true"]:last', thisQuestion).attr('data-visible', 'false').hide();
$('.inserted-button.add', thisQuestion).show();
if ($('[data-visible="true"]', thisQuestion).length == 0) {
$('.inserted-button.remove', thisQuestion).hide();
}
$('.inserted-button.remove', thisQuestion).blur();
}
// Initially hide all except first row or any rows with populated inputs
$(relevantRows).slice(1).each(function(i) {
$( this ).attr('data-visible', 'false').hide();
$('input[type=text]', this).each(function(i) {
if ($.trim($(this).val()) != '') {
$(this).closest('tr').attr('data-visible', 'true').show();
$('.inserted-button.remove', thisQuestion).show();
}
});
});
}
}
// Call the function with a question ID
varLengthArray({QID});
});
Change the texts in addContent and removeContent to translate the buttons.
Default answers in array questions
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
Array questions have no default answers. This script checks one answer in every row of an array that has no answer yet. For example, it can preselect the middle of a scale.
Add the script to the source of the question text and replace A1 with the code of the answer to check:
<script type="text/javascript">
$(document).on('ready pjax:scriptcomplete', function () {
// Pre-check the answer with code A1 in every row that has no answer yet.
// For a dual scale array, add the scale as third parameter: 0 (left) or 1 (right).
checkDefaultAnswer({QID}, 'A1');
function checkDefaultAnswer(qID, answerCode, scale) {
$('#question' + qID + ' tr.answers-list').each(function () {
var radios = $('input[type="radio"]', this);
if (scale === 0 || scale === 1) {
radios = radios.filter('[name$="#' + scale + '"]');
}
var answered = radios.filter(':checked').filter(function () {
return this.value !== '';
}).length > 0;
if (!answered) {
radios.filter('[value="' + answerCode + '"]').trigger('click');
}
});
}
});
</script>
For an Array dual scale question, add the scale as third parameter: 0 for the left scale, 1 for the right scale. For example, checkDefaultAnswer({QID}, 'B2', 1); checks the answer B2 on the right scale.
Toggle visibility of groups
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
In a survey shown on one page (Format: All in one), the script hides all question groups and adds a button with the group name above each group. Participants click the button to show or hide the group. Groups with an unanswered mandatory question or an error stay visible after a participant tries to submit the page.
Add the script to the source of a question text in the first group:
<script type="text/javascript">
$(document).on('ready pjax:scriptcomplete', function () {
$('.group-outer-container').each(function (i) {
var group = $(this);
var groupTitle = $.trim($('.group-title', group).text()) || 'Group ' + (i + 1);
var toggler = $('<button type="button" class="btn btn-outline-secondary w-100 mb-3 group-toggler"></button>')
.text(groupTitle)
.insertBefore(group);
toggler.on('click', function () {
group.toggle();
});
// Hide the group, unless it has an unanswered mandatory question or an error
if ($('.ls-error-mandatory, .has-error, .input-error', group).length === 0) {
group.hide();
}
});
});
</script>
Suggest answers for text inputs (autocomplete)
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
While participants type into a short free text question, the browser suggests matching answers from a list. The script uses the HTML datalist element, so no plugin is needed. Participants can still enter text that is not in the list.
Add the script to the source of the question text and replace the list with your suggestions:
<script type="text/javascript">
$(document).on('ready pjax:scriptcomplete', function () {
// The suggestions - modify as you wish
var suggestions = ['Austria', 'Belgium', 'Bulgaria', 'Croatia', 'Cyprus', 'Czechia', 'Denmark'];
var listId = 'suggestions{QID}';
if ($('#' + listId).length) { return; }
var list = $('<datalist></datalist>').attr('id', listId);
$.each(suggestions, function (i, item) {
list.append($('<option></option>').attr('value', item));
});
$('#question{QID} input[type="text"]').attr('list', listId).after(list);
});
</script>
For long lists, lists from a file or a database, or when participants may only choose from the list, use one of these extensions instead:
- Searchable dropdown question theme for a List (Dropdown) question
- autoComplete plugin: suggestions from a CSV file
- selectQuestionBy plugin: suggestions from a single choice question or a label set
- SelectQuestionByResponses plugin: suggestions from the responses of another survey
Last option of an Array (Numbers) checkbox row excludes the others
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
In an Array (Numbers) question with checkboxes (Checkbox layout set to On), the last column becomes a "None" option: checking it unchecks all other checkboxes of the row, and checking another checkbox unchecks it.
Add the script to the source of the question text:
<script type="text/javascript">
$(document).on('ready pjax:scriptcomplete', function () {
// In each row, the last checkbox excludes all other checkboxes of the row
$('#question{QID} tr.subquestion-list').each(function () {
var boxes = $('input[type="checkbox"]', this);
var lastBox = boxes.last();
boxes.on('change', function () {
if (!this.checked) { return; }
if (this === lastBox[0]) {
boxes.not(lastBox).filter(':checked').trigger('click');
} else if (lastBox.is(':checked')) {
lastBox.trigger('click');
}
});
});
});
</script>
To use another column, replace boxes.last() with boxes.eq(0) for the first column, boxes.eq(1) for the second, and so on.
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
The script adds copies of the Previous and Next (or Submit) buttons above the questions.
Add it to custom.js of your theme (see Adding your own CSS and JavaScript) to show the buttons on all pages, or between <script> tags in a question text to show them on one page:
$(document).on('ready pjax:scriptcomplete', function () {
if ($('#navigator-top').length || !$('#ls-button-submit').length) { return; }
var topNavigator = $('<div id="navigator-top" class="d-flex justify-content-between mb-3"></div>');
$('#ls-button-previous, #ls-button-submit').each(function () {
$(this).clone().attr('id', this.id + '-top').removeAttr('accesskey').appendTo(topNavigator);
});
topNavigator.insertBefore($('.group-outer-container').first());
});
Opt-out link in the survey
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
Invitation emails can contain an opt-out link ({OPTOUTURL}, see Email templates). To offer the same link inside the survey, add a link like this to a question text or group description. It needs no JavaScript.
<p><a href="https://www.example.org/index.php/optout/tokens?surveyid={SID}&token={TOKEN}&langcode={LANG}">Click here to opt out of this survey.</a></p>
Replace https://www.example.org/index.php with the address of your survey site, up to and including index.php. The link works only for participants who started the survey with an access code (see Survey participants). It opens a page where the participant confirms the opt-out.
Track participants across surveys without access codes
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
To link the answers of the same person in several surveys without access codes, the script builds an ID from a few answers only the participant knows, such as the first letter of their mother's first name and their birth month. Only a hash of these answers is stored, not the answers themselves. Use the same question in every survey, and the same person gets the same ID.
The ID is pseudonymous, not anonymous: with few answer options, the answers behind a hash can be found by trying all combinations. Add more fields, or fields with more options, if that matters.
- Create a short free text question.
- Add this code to the source of the question text. Complete the lists of options.
<p>These answers are used to create your ID. Only the ID is stored, not the answers.</p>
<table>
<tr>
<td>First letter of your mother's first name</td>
<td>
<select id="idField1">
<option value=""></option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<!-- add the other letters -->
</select>
</td>
</tr>
<tr>
<td>Your birth month</td>
<td>
<select id="idField2">
<option value=""></option>
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<!-- add the other months -->
</select>
</td>
</tr>
</table>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js"></script>
<script type="text/javascript">
$(document).on('ready pjax:scriptcomplete', function () {
var idInput = $('#question{QID} input[type="text"]');
idInput.prop('readonly', true);
// idInput.hide(); // uncomment to hide the ID
$('#idField1, #idField2').on('change', function () {
if ($('#idField1').val() === '' || $('#idField2').val() === '') {
idInput.val('').trigger('keyup');
} else {
var hash = CryptoJS.SHA1($('#idField1').val() + $('#idField2').val()).toString();
idInput.val(hash).trigger('keyup');
}
});
});
</script>
The script loads the CryptoJS library from a CDN and stores the SHA-1 hash of the answers in the short free text question.
Disable or hide selected fields in a matrix question
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
The script makes single fields of an Array (Texts) or Array (Numbers) question read-only or hides them. Rows are counted from 0; columns are named by the code of the column subquestion.
Add the script to the source of the question text and change the rows and column codes:
<script type="text/javascript">
$(document).on('ready pjax:scriptcomplete', function () {
var thisQuestion = $('#question{QID}');
// First row, column with the code C1: read-only
$('tr.subquestion-list', thisQuestion).eq(0).find('td.answer_cell_C1 input[type="text"]').prop('readonly', true);
// Second row, column with the code C2: hidden
$('tr.subquestion-list', thisQuestion).eq(1).find('td.answer_cell_C2 input[type="text"]').hide();
});
</script>
Dropdowns in the cells of Array (Texts)
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
This script replaces the text fields of an Array (Texts) question with dropdowns that offer your own choices, for example "Yes", "No" and "Do not know". (For dropdowns with numbers only, use an Array (Numbers) question: it shows dropdowns by default.)
Add the script to the source of the question text. In options, list the code and the label of each choice. With storeLabels = false, the response data contains the codes; with true, it contains the labels.
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete', function () {
var thisQuestion = $('#question{QID}');
// The choices: [code, label]
var options = [
['1', 'Yes'],
['2', 'No'],
['3', 'Do not know']
];
// false: store the code, true: store the label
var storeLabels = false;
$('.answer-item input:text', thisQuestion).each(function () {
var input = $(this);
var select = $('<select class="form-select inserted-select"><option value="">Please choose...</option></select>');
$.each(options, function (i, option) {
select.append($('<option></option>').val(option[0]).text(option[1]));
});
// Show an earlier answer
var current = $.trim(input.val());
if (current !== '') {
$.each(options, function (i, option) {
if (current === (storeLabels ? option[1] : option[0])) {
select.val(option[0]);
}
});
}
select.on('change', function () {
var code = $(this).val();
var label = $('option:selected', this).text();
input.val(code === '' ? '' : (storeLabels ? label : code)).trigger('keyup');
});
input.hide().after(select);
});
});
</script>
Add a prefix or suffix to Array (Texts)
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
The script adds a text after the fields of chosen columns of an Array (Texts) question, for example a currency or unit. (Short free text and numerical questions have built-in Answer prefix and Answer suffix settings: see QS:Prefix and QS:Suffix.)
Add the script to the source of the question text. In the call, list the column codes and their suffixes:
<script type="text/javascript">
$(document).on('ready pjax:scriptcomplete', function () {
// Column codes and their suffixes - modify as you wish
addSuffix({QID}, { 'C1': 'in €', 'C2': 'in %' });
function addSuffix(qID, suffixes) {
$.each(suffixes, function (columnCode, suffix) {
$('#question' + qID + ' td.answer_cell_' + columnCode + ' input[type="text"]').each(function () {
$(this).wrap('<div class="input-group"></div>');
$(this).after($('<span class="input-group-text"></span>').text(suffix));
});
});
}
});
</script>
For a prefix, replace $(this).after(...) with $(this).before(...).
Cross out options in a multiple choice question
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
In a long Multiple choice question, participants can cross out options that don't apply, as they would on paper. The script adds a red X before each option. Clicking it greys out and strikes through the option and unchecks it. Clicking it again, or checking the option, undoes this. The crossing out is not saved.
Add the script to the source of the question text:
<script type="text/javascript">
$(document).on('ready pjax:scriptcomplete', function () {
var thisQuestion = $('#question{QID}');
$('li.checkbox-item', thisQuestion).each(function () {
var item = $(this);
var checkbox = $('input[type="checkbox"]', item);
var label = $('label', item).first();
var crossOut = $('<span class="cross-out" role="button" title="Cross out">X</span>')
.css({ 'color': 'red', 'font-weight': 'bold', 'cursor': 'pointer', 'margin-right': '10px' });
item.find('.row').first().prepend($('<div class="col-auto"></div>').append(crossOut));
crossOut.on('click', function () {
var crossed = !item.hasClass('crossed-out');
item.toggleClass('crossed-out', crossed);
label.css({ 'color': crossed ? '#bfbfbf' : '', 'text-decoration': crossed ? 'line-through' : '' });
if (crossed && checkbox.is(':checked')) {
checkbox.trigger('click');
}
});
checkbox.on('change', function () {
if (this.checked && item.hasClass('crossed-out')) {
item.removeClass('crossed-out');
label.css({ 'color': '', 'text-decoration': '' });
}
});
});
});
</script>
Select all option in a multiple choice question
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
The last option of a multiple choice question checks all other options, for example "All of the above". While it is checked, the other options can't be changed. All checked options are saved.
- Create the multiple choice question with "All of the above" as the last subquestion.
- Add the script to the source of the question text:
<script type="text/javascript">
$(document).on('ready pjax:scriptcomplete', function () {
var thisQuestion = $('#question{QID}');
var allBox = $('input[type="checkbox"]', thisQuestion).last();
var otherBoxes = $('input[type="checkbox"]', thisQuestion).not(allBox);
function setOthers(checked) {
otherBoxes.each(function () {
if (this.checked !== checked) {
$(this).prop('checked', checked);
checkconditions(this.value, this.name, this.type);
}
});
otherBoxes.prop('disabled', checked);
}
if (allBox.is(':checked')) {
setOthers(true);
}
allBox.on('change', function () {
setOthers(this.checked);
});
// Enable the checkboxes again before the page is sent, so that the answers are saved
$('#ls-button-previous, #ls-button-submit').on('click', function () {
otherBoxes.prop('disabled', false);
});
});
</script>
For the opposite, an option that unchecks all others ("None of these"), use the built-in Exclusive option setting. See QS:Exclusive option.
Implicit Association Test (IAT)
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
This script turns an Array (Texts) question into an Implicit Association Test. The words are shown one at a time. Participants assign each word to the left or the right term with the E or I key, or with the buttons below the box on touch screens. For each word, the chosen term and the time in milliseconds are stored.

- Create an Array (Texts) question.
- Add the words as subquestions of the Y scale (rows).
- Add two subquestions to the X scale (columns): one with the code
KEY(for example "Term chosen") and one with the codeMS(for example "Time in ms"). If you use other codes, changetermColumnandtimeColumnin the script. - To show the words in random order, set Random order to On (see QS:Random order). The script finds the columns by their codes, so the order of the columns doesn't matter.
- Add the following to the source of the question text and change the texts at the top of the script:
<div class="iat-wrapper">
<div class="iat-left-label"></div>
<div class="iat-right-label"></div>
<div class="iat-word"></div>
<div class="iat-instructions"></div>
</div>
<div class="iat-buttons">
<button type="button" class="btn btn-outline-secondary iat-button" data-side="left">E</button>
<button type="button" class="btn btn-outline-secondary iat-button" data-side="right">I</button>
</div>
<style type="text/css">
.iat-wrapper {
position: relative;
max-width: 600px;
height: 300px;
margin: 0 auto 10px auto;
color: #D0DBE5;
background-color: #2C3E50;
font-size: 21px;
}
.iat-left-label {
position: absolute;
left: 10px;
top: 10px;
}
.iat-right-label {
position: absolute;
right: 10px;
top: 10px;
}
.iat-word {
position: absolute;
width: 100%;
top: 35%;
text-align: center;
font-size: 36px;
}
.iat-instructions {
position: absolute;
width: 100%;
bottom: 10px;
padding: 0 10px;
text-align: center;
font-size: 16px;
}
.iat-buttons {
display: flex;
justify-content: space-between;
max-width: 600px;
margin: 0 auto;
}
.iat-button {
width: 100px;
font-size: 24px;
}
</style>
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete', function () {
// Texts - modify as you wish
var leftTerm = 'Flowers';
var rightTerm = 'Insects';
var instructions = 'Press E for the left term and I for the right term. Press E or I to start.';
var finishText = 'Done. Thank you!';
// Codes of the two columns (subquestions of the X scale)
var termColumn = 'KEY';
var timeColumn = 'MS';
var thisQuestion = $('#question{QID}');
var rows = $('table.subquestion-list tr.subquestion-list', thisQuestion);
var started = false;
var startTime = 0;
$('.iat-left-label', thisQuestion).text(leftTerm);
$('.iat-right-label', thisQuestion).text(rightTerm);
$('.iat-instructions', thisQuestion).text(instructions);
$('table.subquestion-list', thisQuestion).hide();
// The first word that has no answer yet
function nextRow() {
return rows.filter(function () {
return $('.answer_cell_' + termColumn + ' input', this).val() === '';
}).first();
}
function showWord() {
var row = nextRow();
if (row.length === 0) {
$('.iat-left-label, .iat-right-label, .iat-instructions, .iat-buttons', thisQuestion).hide();
$('.iat-word', thisQuestion).text(finishText);
$(document).off('keydown.iat');
return;
}
$('.iat-word', thisQuestion).text($.trim($('.answertext', row).text()));
startTime = Date.now();
}
function answer(side) {
if (!started) {
started = true;
showWord();
return;
}
var row = nextRow();
if (row.length === 0) {
return;
}
$('.answer_cell_' + timeColumn + ' input', row).val(Date.now() - startTime).trigger('keyup');
$('.answer_cell_' + termColumn + ' input', row).val(side === 'left' ? leftTerm : rightTerm).trigger('keyup');
showWord();
}
$(document).off('keydown.iat').on('keydown.iat', function (event) {
var key = (event.key || '').toLowerCase();
if ((key === 'e' || key === 'i') && !$(event.target).is('input, textarea, select')) {
event.preventDefault();
answer(key === 'e' ? 'left' : 'right');
}
});
$('.iat-button', thisQuestion).on('click', function () {
answer($(this).data('side'));
});
if (nextRow().length === 0) {
showWord();
}
});
</script>
The table of the question is hidden. If participants come back to the page, only the words without an answer are shown again.
Van Westendorp pricing sliders
Tested with LimeSurvey 7.9 and Fruity TwentyThree.
For the Van Westendorp price sensitivity method, participants set four prices that must rise from top to bottom: too cheap, cheap, expensive, too expensive. This script couples the sliders of a Multiple numerical input question: when a participant moves a slider above a lower one, the sliders below it move up along with it, and when a participant moves a slider below a higher one, the sliders above it move down. A slider can't be moved so far that the others have no room between the minimum and the maximum.

- Create a Multiple numerical input question, for example with the code
PS. - Add four subquestions in rising order, for example
TOOCHEAP,CHEAP,EXPENSIVEandTOOEXP. Leave Random order off: the script couples the sliders in the order they are shown. - Set Use slider layout to On and set the slider minimum, maximum and accuracy (see QS:Slider layout). Set
gapin the script to the accuracy, so that neighbouring prices differ by at least one step. - As a fallback for participants without JavaScript, add a Question validation equation such as
PS_TOOCHEAP < PS_CHEAP and PS_CHEAP < PS_EXPENSIVE and PS_EXPENSIVE < PS_TOOEXP(see Validation: make sure the answers you get are usable). - Add this script to the source of the question text:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete', function () {
// Smallest distance between two neighbouring sliders - use the step of the sliders
var gap = 1;
var thisQuestion = $('#question{QID}');
var busy = false;
function toNumber(value) {
return parseFloat(String(value).replace(',', '.'));
}
// When a slider moves, push the higher sliders up and the lower sliders down
thisQuestion.on('slide slideStop', 'input[name$="slid"]', function (event) {
var sliders = $('input[name$="slid"]', thisQuestion);
// Only react to the participant, not to the setup of the sliders
var ready = window.activeSliders && sliders.toArray().every(function (slider) {
return window.activeSliders['s' + slider.name.replace(/slid$/, '')];
});
if (busy || !ready || $('#answer' + this.name.replace(/slid$/, '')).hasClass('slider-untouched')) {
return;
}
busy = true;
var movedIndex = sliders.index(this);
var movedValue = toNumber(event.value);
// Keep room for the other sliders between the minimum and the maximum
var movedSlider = window.activeSliders['s' + this.name.replace(/slid$/, '')];
var settings = movedSlider.getSettings();
var lowest = toNumber(settings.min) + movedIndex * gap;
var highest = toNumber(settings.max) - (sliders.length - 1 - movedIndex) * gap;
if (movedValue < lowest || movedValue > highest) {
movedValue = Math.min(Math.max(movedValue, lowest), highest);
movedSlider.setValue(String(movedValue));
}
sliders.each(function (index) {
if (index === movedIndex) {
return;
}
var name = this.name.replace(/slid$/, '');
var answer = $('#answer' + name);
var current = toNumber(answer.val());
if (isNaN(current)) {
current = -Infinity;
}
var limit = movedValue + (index - movedIndex) * gap;
if ((index > movedIndex && current < limit) || (index < movedIndex && current > limit)) {
$('#javatbd' + name + ' .slider-container').removeClass('slider-untouched');
answer.removeClass('slider-untouched');
window.activeSliders['s' + name].setValue(String(limit));
}
});
busy = false;
});
});
</script>
Sliders that the participant hasn't touched yet stay empty when a slider below them moves; they get a value only when they have to move up.
Question themes from the community
Some larger workarounds were turned into question themes. They were made for LimeSurvey 5 and 6 and not tested with LimeSurvey 7. Install a theme with Upload & install on the Themes page (see Install a question theme) and test it in the preview before you use it in a live survey.
| Question theme | What it does | Made for |
|---|---|---|
| Card sorting | Participants drag items into "buckets". Based on a Multiple short text question; the bucket number is saved for each item. | LimeSurvey 5 and 6 |
| Social Value Orientation (pay-off matrix) | Shows the answers of a List (Radio) question as a pay-off matrix. | LimeSurvey 5 and 6 |
| Image interest points | Participants drop "positive" and "negative" markers with comments on an image. Based on a Multiple short text question. | LimeSurvey 5 and 6 |
| Range slider | A slider with two handles for a range; the two values are saved in a Multiple numerical input question. | LimeSurvey 5 and 6 |
| Slider controls | Buttons for fine control of the sliders of a Multiple numerical input question. | LimeSurvey 6 |