Hi,
I need your help with a javascript code.
I have an array question with checkboxes. I am trying to exclude all other options in a row if the user the last one. I've this article where you can find a javascript code to do it:
manual.limesurvey.org/wiki/Workarounds:_..._Excludes_All_Others
The code proposed is:
I've used it, but something weird happens. Please, have a look to my survey here:
enquestas.com/sv/index.php/333559/lang-es
Code only works in the last row, but not in the 2 first one.
I am using Limesurvey V2.0
Can you help me, please?
Many thanks in advance
Regards
Víctor
I need your help with a javascript code.
I have an array question with checkboxes. I am trying to exclude all other options in a row if the user the last one. I've this article where you can find a javascript code to do it:
manual.limesurvey.org/wiki/Workarounds:_..._Excludes_All_Others
The code proposed is:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Call the exclude function using question ID(s)
excludeOpt (QQ);
// A function to make the last option in each array row exclusive
function excludeOpt (qID) {
// Add some classes to the checkboxes so we can manipulate them
$('#question'+qID+' table.question tbody td').addClass('normalOpt');
$('#question'+qID+' table.question tbody').each(function(i) {
$('td:last', this).removeClass('normalOpt').addClass('exlusiveOpt')
});
// A listener on the checkbox cells
$('#question'+qID+' table.question tbody td').click(function (event) {
// Set some vars
var el = $(this).parent();
var optLength = $('td', el).length
// Uncheck the appropriate boxes in a row
if ($(this).hasClass('normalOpt')) {
$('td:last input[type=checkbox]', el).attr('checked', false);
}
else {
$('td', el).each(function(i) {
if (i < (optLength - 1)) {
$('input[type=checkbox]', this).attr('checked', false);
}
});
}
});
// A listener on the checkboxes
$('#question'+qID+' table.question tbody td input[type=checkbox]').click(function (event) {
// Set some vars
var el2 = $(this).parent().parent();
var optLength = $('td', el2).length
// Uncheck the appropriate boxes in a row
if ($(this).parent().hasClass('normalOpt')) {
$('td:last input[type=checkbox]', el2).attr('checked', false);
}
else {
$('td', el2).each(function(i) {
if (i < (optLength - 1)) {
$('input[type=checkbox]', this).attr('checked', false);
}
});
}
});
}
});
</script>
I've used it, but something weird happens. Please, have a look to my survey here:
enquestas.com/sv/index.php/333559/lang-es
Code only works in the last row, but not in the 2 first one.
I am using Limesurvey V2.0
Can you help me, please?
Many thanks in advance
Regards
Víctor