Oops here is the link:
survey.cirano.qc.ca/index.php/171722?lang=fr
And I am talking about that code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify this question
var thisQuestion = $('#question{QID}');
// Insert the "totals" elements
var insertedEl = '<li class="multiplenumerichelp help-item">\
<span class="label">Remaining: </span>\
<span class="dynamic_remaining">\
<span>100</span>\
%</span>\
</li>\
<li class="multiplenumerichelp help-item">\
<span class="label">Total: </span>\
<span class="dynamic_sum">\
<span>0</span>\
%</span>\
</li>';
$('ul.subquestions-list', thisQuestion).append(insertedEl);
// A listener on the inputs
$('input[type=text]', thisQuestion).bind('change keyup', function(e) {
handleInputs(thisQuestion);
});
$('input[type=text]', thisQuestion).bind('paste', function(e) {
setTimeout(function () {
handleInputs(thisQuestion);
}, 100);
});
// Initialize sum values
handleInputs(thisQuestion);
});
// A function to calculate totals in a multiple numeric
function handleInputs(question) {
var thisQuestion = $(question);
var answered = 0;
var sumTotal = 0;
$('input[type=text]', thisQuestion).each(function(i) {
sumTotal = Number(sumTotal) + Number($(this).val());
if($(this).val() != '') {
answered = Number(answered) + 1;
}
});
$('span.dynamic_remaining span', thisQuestion).text(100 - sumTotal);
$('span.dynamic_sum span', thisQuestion).text(sumTotal);
$('span.dynamic_sum', thisQuestion).removeClass('good error');
if(answered > 0 && sumTotal == 100) {
$('span.dynamic_sum', thisQuestion).addClass('good');
}
else if(answered > 0) {
$('span.dynamic_sum', thisQuestion).addClass('error');
}
}
</script>