I have a question type array with five sub-questions. In each sub-question the respondent can put a value from 1 to 5.
I want to make the respondent put different values in each sub-question. For example, if the sub-question 1 put the value 3, in the sub-questions 2, 3, 4 and 5 he can not put the value 3.
Set up your survey to use JavaScript and add this script to the array question source:
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// The error message
var errorMsg = 'You can only select one answer per column';
// Identify the question
var qID = {QID};
var thisQuestion = $('#question'+qID);
// Listener on the radios
$('.radio-item', thisQuestion).click(function(event) {
// Check for more than one answer per column
var answerCode = $(this).attr('class').split('answer_cell_00')[1].split(' ')[0];
if($('.answer_cell_00'+answerCode+' input[type="radio"]:checked', thisQuestion).length > 1) {
alert(errorMsg);
$('input[type="radio"]', this).attr('checked', false);
}
});
});
</script>
Cheers,
Tony Partner Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
I had added the script to the source of the array question, but still can't work. It should be have different answer on 1st, 2nd, 3th, 4th and 5th mention. Any suggestion? Thanks.
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// The error message
var errorMsg = 'You can only select one answer per row';
// Identify the question
var qID = {QID};
var thisQuestion = $('#question'+qID);
// Listener on the radios
$('.radio-item', thisQuestion).click(function(event) {
// Check for more than one answer per row
var thisRow = $(this).closest('tr');
if($('input[type="radio"]:checked', thisRow).length > 1) {
alert(errorMsg);
$('input[type="radio"]', this).attr('checked', false);
}
});
});
</script>