Check Your Question Items
Sometimes the multi-select question items are better displayed as a series of checkboxes rather than a multi-select listbox where you need to option-click each option after the first one and hope you didn't mess up the other options you've selected. This script will make that transformation.
Here is a screencast of me demonstrating how to implement the script and what it will look like:
There are two steps involved in implementing the script. The first is to copy/paste this script into text interface field#259:
<script> /* Tested in TDS 14.0 */ /* Add to text interface field # 259 */ /* Add <input type="hidden" name="custom-UI" value="checkboxes" /> to question item instructions to activate */ $(document).ready(function () { // check for any multi-select questions tagged to be checkboxes $('input[name="custom-UI"]').each(function () { if ($(this).val() == "checkboxes") { // grab the checkbox options that will be necessary var qstName = $(this).parent().next().find('select').attr('name'); var qstOptions = new Array(); var selOptions = new Array(); $(this).parent().next().find('option').each( function() { qstOptions.push($(this).val() + "|" + $(this).text().trim()); if ($(this).attr('selected') == "selected") { selOptions.push($(this).val() + "|" + $(this).text().trim()); } }); // hide the existing listbox $(this).parent().next().find('select').css('display','none'); // build the new checkbox interface $(this).parent().next().prepend('<div name="custom-UI-' + qstName + '"></div>'); for (var i=0; i < qstOptions.length; i++) { if (i > 0) { $('div[name="custom-UI-' + qstName + '"]').append('<br />'); } var inpOptions = qstOptions[i].split('|'); $('div[name="custom-UI-' + qstName + '"]').append('<label><input type="checkbox" name="' + inpOptions[1] + '" value="' + inpOptions[0] + '">' + inpOptions[1] + '</label>'); if (selOptions.indexOf(qstOptions[i]) != -1) { $('div[name="custom-UI-' + qstName + '"]').find('input[name="' + inpOptions[1] + '"]').prop('checked', true); } } // assign the event handlers to the checkboxes to keep the existing listbox updated $('div[name="custom-UI-' + qstName + '"]').find('input').change(function () { checkboxChange($(this).parent().parent().attr('name'), $(this).val()); }); } }); }); function checkboxChange (questionitem, valuechanged) { // this will be the event handler for the changed checkboxes var isselected = false; if ($('div[name="' + questionitem + '"]').find('input[value="' + valuechanged + '"]').prop('checked') == true) { isselected = true; } $('div[name="' + questionitem + '"]').next().find('option[value="' + valuechanged + '"]').prop('selected',isselected); } </script>
This script will now be embedded in the applicant's questionnaire view. You are now ready to add the following tag to any multi-select question items that you want to change from a multi-select listbox to a series of checkboxes:
<input type="hidden" name="custom-UI" value="checkboxes" />
That's it. Now, whenever an applicant opens up a questionnaire with that question item, the interface will be transformed by the script you embedded in text interface field#259.
Here's what the script is doing...
When the page finishes loading, it is looking for any 'input' tags that have the name of 'Custom-UI' and a value of 'checkboxes' and running a function on each one. This will find of question items on the page that need to be changed.
First, the function will create a couple of arrays. One with all the option values for the multi-select question item, and another with all the options values for that question item that have been selected by the user because this might be a questionnaire the user has 'saved' and is returning to finish.
Next, it hides the existing listbox for the question item. We'll still need it though. It is going to function as the element that is getting passed in to the server.
Then, the script builds the checkboxes based on the first array and then marks the selected checkboxes based on the second array.
Finally, the script assigns an event-handler to fire off a function whenever one of those checkboxes change. That function will synchronize the checkbox's state with the hidden listbox.
As I mention in the screencast video, there are a few potential updates to this in the future. The obvious one is to put the checkboxes in multiple columns instead of a single column. This would preserve vertical space and also look nicer. Another potential way to update this script would be to enforce a maximum # of selections in a multi-select question item. Yet another potential update to this would be to display the options in a different manner. Maybe instead of having them appear as checkboxes, they could be displayed as a row of round buttons that you can click on and off. When it comes to ways to improve the UX on the questionnaire page, there are a lot of ideas that could be tossed around and implemented with just a bit of javascript.
This one  has been tested in TDS 14.0.












