The HTML structure of that question type was changed in LS 2.5x.
Here is an updated script to accommodate those changes (note that the HTML structure may be changed again in future releases).
Sample survey attached:
Here is an updated script to accommodate those changes (note that the HTML structure may be changed again in future releases).
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify this question
var thisQuestion = $('#question{QID}');
// Insert the "totals" elements
var insertedEl = '<tr>\
<td class="hide-on-small-screen"></td>\
<td>\
<div class="multiplenumerichelp help-block pull-right">\
<div class="label label-default">\
<label>Restant :</label>\
<span class="dynamic_remaining"><span>100</span>%</span>\
</div>\
</div>\
</td>\
</tr>\
<tr>\
<td class="hide-on-small-screen"></td>\
<td>\
<div class="multiplenumerichelp help-block pull-right">\
<div class="label label-default">\
<label class="">Total :</label>\
<span class="dynamic_sum"><span>0</span>%</span>\
</div>\
</div>\
</td>\
</tr>';
$('tr.answer-item:last', thisQuestion).after(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>
Sample survey attached: