- Posts: 17
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// A function to pre-check a column of an array
function checkedDefault(qID, column) {
var checkedCol = column - 1;
$('#question' + qID + ' table.question tbody tr').each(function(i) {
if ($('input.radio[checked=true]', this).length == 0) {
$('input.radio:eq(' + checkedCol + ')', this).attr('checked', true);
}
});
}
// Call the function with a question ID and column number
checkedDefault(QQ, CC);
});
</script>
hgauthier wrote: Bonjour,
Je me permets de relancer le sujet car j'ai le même problème, et je n'ai pas trouvé la réponse.
J'ai un tableau avec 3 colonnes et 7 lignes. Je voudrais qu'une de mes lignes (celle qui correspond à l'option de réponse "rien", code A6) soit pré-remplie pour mes trois colonnes comme dans l'exemple lorsque qu'on sélectionne le type "tableau en colonne" (cf pièce-jointe).
Je suis novice en JS mais je pensais copier ce script, trouvé dans le manuel :
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Scale to set the default answer on
var defaultAnsweredScale = 2;
// Column of that scale to set as default answer
var defaultAnsweredColumn = 3;
// Identify this question
var thisQuestion = $('#question{self.qid}');
// Identify the scales and columns
$('.answer-item[class^="answer_cell_1"]', thisQuestion).addClass('scale-1-item');
$('.answer-item[class^="answer_cell_2"]', thisQuestion).addClass('scale-2-item');
$('tr.answers-list', thisQuestion).each(function(i) {
$('.scale-1-item', this).each(function(i) {
$(this).addClass('scale-1-column-'+(i+1)+'-item');
});
$('.scale-2-item', this).each(function(i) {
$(this).addClass('scale-2-column-'+(i+1)+'-item');
});
});
// Click the default answers
$('tr.answers-list', thisQuestion).each(function(i) {
if($('.scale-'+defaultAnsweredScale+'-item input[type="radio"]:checked', this).length == 0) {
$('.scale-'+defaultAnsweredScale+'-column-'+defaultAnsweredColumn+'-item input[type="radio"]:last', this).click();
}
});
});
</script>