- Posts: 16
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<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>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Call the exclude function using question ID excludeOpt ({QID}); }); // A function to make the last option in each array row exclusive function excludeOpt (qID) { var thisQuestion = $('#question'+qID) // Add some classes to the checkbox cells $('table.question tbody td', thisQuestion).addClass('normalOpt'); $('table.question tbody tr', thisQuestion).each(function(i) { $('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt') }); // A listener on the checkbox cells $('table.question tbody td', thisQuestion).click(function (event) { // Set some vars var thisRow = $(this).closest('tr'); // Uncheck the appropriate boxes in a row if ($(this).hasClass('normalOpt')) { $('.exlusiveOpt input[type=checkbox]', thisRow).attr('checked', false); } else { $('.normalOpt input[type=checkbox]', thisRow).attr('checked', false); } }); // A listener on the checkboxes $('table.question tbody td input[type=checkbox]', thisQuestion).click(function (event) { // Set some vars var thisRow = $(this).closest('tr'); var thisCell = $(this).closest('td'); // Uncheck the appropriate boxes in a row if ($(thisCell).hasClass('normalOpt')) { $('.exlusiveOpt input[type=checkbox]', thisRow).attr('checked', false); } else { $('.normalOpt input[type=checkbox]', thisRow).attr('checked', false); } }); } </script>
< script type = "text/javascript" charset = "utf-8" > $(document).ready(function () { // Call the function with a question ID and column number Once var wQuit = true; if (wQuit) { checkedDefault({ QID }, 12); wQuit = false; }; // Call the exclude function using question ID excludeOpt({ QID }); }); // A function to pre-check a column of an array function checkedDefault(qID, column) { var checkedCol = column - 1; $('#question' + qID + ' tr.subquestions-list').each(function (i) { if ($('input.checkbox:checked', this).length == 0) { $('input.checkbox:eq(' + checkedCol + ')', this).prop('checked', true); $('input.checkbox:eq(' + checkedCol + ')', this).parent().find('input[type="hidden"]').val(1); } }); } // A function to make the last option in each array row exclusive function excludeOpt(qID) { var thisQuestion = $('#question' + qID) // Add some classes to the checkbox cells $('table.subquestions-list tbody td', thisQuestion).addClass('normalOpt'); $('table.subquestions-list tbody tr', thisQuestion).each(function (i) { $('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt') }); // A listener on the checkbox cells $('table.subquestions-list tbody td', thisQuestion).click(function (event) { // Set some vars var thisRow = $(this).closest('tr'); // Uncheck the appropriate boxes in a row if ($(this).hasClass('normalOpt')) { $('.exlusiveOpt input[type=checkbox]', thisRow).attr('checked', false); } else { $('.normalOpt input[type=checkbox]', thisRow).attr('checked', false); } }); // A listener on the checkboxes $('table.subquestions tbody td input[type=checkbox]', thisQuestion).click(function (event) { // Set some vars var thisRow = $(this).closest('tr'); var thisCell = $(this).closest('td'); // Uncheck the appropriate boxes in a row if ($(thisCell).hasClass('normalOpt')) { $('.exlusiveOpt input[type=checkbox]', thisRow).attr('checked', false); } else { $('.normalOpt input[type=checkbox]', thisRow).attr('checked', false); } }); } < / script >
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); //// Check the last option in each row by default //// $('tr.subquestions-list', thisQuestion).each(function(i) { if ($('input.checkbox:checked', this).length == 0) { $('input.checkbox:last', this).prop('checked', true); $('input.checkbox:last', this).parent().find('input[type="hidden"]').val(1); } }); //// Make the last option in each array row exclusive //// // Add some classes to the checkbox cells $('table.subquestions-list tbody td', thisQuestion).addClass('normalOpt'); $('table.subquestions-list tbody tr', thisQuestion).each(function(i) { $('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt') }); // A listener on the checkboxes $('input[type=checkbox]', thisQuestion).change(function (event) { var thisRow = $(this).closest('tr'); var thisCell = $(this).closest('td'); if ($(this).is(':checked') && thisCell.hasClass('normalOpt')) { $('.exlusiveOpt input[type=checkbox]', thisRow).prop('checked', false); $('.exlusiveOpt input[type="hidden"]', thisRow).val(''); } if ($(this).is(':checked') && thisCell.hasClass('exlusiveOpt')) { $('.normalOpt input[type=checkbox]', thisRow).prop('checked', false); $('.normalOpt input[type="hidden"]', thisRow).val(''); } }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Call the exclude function using question ID excludeOpt ({QID}); }); // A function to make the last option in each array row exclusive function excludeOpt (qID) { var thisQuestion = $('#question'+qID) // Add some classes to the checkbox cells $('table.question tbody td', thisQuestion).addClass('normalOpt'); $('table.question tbody tr', thisQuestion).each(function(i) { // Last two coluns are exclusive $('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt'); $('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt'); }); // A listener on the checkboxes $('table.question tbody td input[type=checkbox]', thisQuestion).change(function (event) { if($(this).is(':checked')) { // Set some vars var thisRow = $(this).closest('tr'); var thisCell = $(this).closest('td'); // Uncheck the appropriate boxes in the row if ($(thisCell).hasClass('normalOpt')) { // Non-exclusive $('.exlusiveOpt input[type=checkbox]', thisRow).each(function(i) { $(this).prop('checked', false); $(this).closest('td').find('input[type="hidden"]').attr('value', ''); }); } else { // Exclusive $('input[type=checkbox]', thisRow).not(this).each(function(i) { $(this).prop('checked', false); $(this).closest('td').find('input[type="hidden"]').attr('value', ''); }); } } }); } </script>