- Posts: 18
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Equal sum value does not render the question unacceptable
- slaugh
- Topic Author
- Offline
- New Member
Less
More
9 years 3 months ago #114766
by slaugh
Equal sum value does not render the question unacceptable was created by slaugh
Hi!
Is it possible to set a "equal sum value" but to make it so that it doesn't make the question unacceptable if the participant doesn't respect the set value?
I'd like it to simply warn the participant when his answer is not logical, but not to prohibit him to go to the next page.
I am using LS 2.05+ and the default template.
Here is an active survey with the template I am using and a multiple numerical question with @equal sum value" activated : survey.cirano.qc.ca/index.php/552928/lang-en
Thank you!
Sophie
Is it possible to set a "equal sum value" but to make it so that it doesn't make the question unacceptable if the participant doesn't respect the set value?
I'd like it to simply warn the participant when his answer is not logical, but not to prohibit him to go to the next page.
I am using LS 2.05+ and the default template.
Here is an active survey with the template I am using and a multiple numerical question with @equal sum value" activated : survey.cirano.qc.ca/index.php/552928/lang-en
Thank you!
Sophie
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
9 years 3 months ago - 9 years 3 months ago #114795
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Equal sum value does not render the question unacceptable
To do that you would need to disable the LimeSurvey "Equals sum value" setting and use JavaScript to insert and handle the "totals" elements after page load.
Add something like this to the source of the question:
Add something like this to the source of the question:
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>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 3 months ago by tpartner.
The following user(s) said Thank You: slaugh
The topic has been locked.
- slaugh
- Topic Author
- Offline
- New Member
Less
More
- Posts: 18
- Thank you received: 0
9 years 3 months ago #114797
by slaugh
Replied by slaugh on topic Equal sum value does not render the question unacceptable
Thank you so much. It seems to work perfectly!
I'd like tot do the same thing with a question where the "equal_sum_value" is a number given by the participant in a previous question.
I guess the coding would be different.
See here for an exemple in an active survey: survey.cirano.qc.ca/index.php/481326/lang-fr
It is the third question (PROVSAL: QID13923) I am concerned about. It appears only if the total of the first question is greater than 0. And the total in third question should be equal to the first question total.
I'd like tot do the same thing with a question where the "equal_sum_value" is a number given by the participant in a previous question.
I guess the coding would be different.
See here for an exemple in an active survey: survey.cirano.qc.ca/index.php/481326/lang-fr
It is the third question (PROVSAL: QID13923) I am concerned about. It appears only if the total of the first question is greater than 0. And the total in third question should be equal to the first question total.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
9 years 3 months ago - 9 years 3 months ago #114808
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Equal sum value does not render the question unacceptable
Well, for this specific case, you could add a listener on "number of employees" question as a control.
Something like this in the source of the "where are they from" question:
Something like this in the source of the "where are they from" question:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify the elements var thisQuestion = $('#question{QID}'); var controlQuestion = thisQuestion.prevAll('.numeric-multi:eq(0)'); var inputs = $('input[type=text]', thisQuestion).add('input[type=text]', controlQuestion); // 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 $(inputs).bind('change keyup', function(e) { handleInputs(thisQuestion, controlQuestion); }); $(inputs).bind('paste', function(e) { setTimeout(function () { handleInputs(thisQuestion, controlQuestion); }, 100); }); // Initialize sum values handleInputs(thisQuestion); }); // A function to calculate totals in a multiple numeric function handleInputs(thisQuestion, controlQuestion) { var thisQuestion = thisQuestion; var controlQuestion = controlQuestion; var controlTotal = 0; var answered = 0; var sumTotal = 0; $('input[type=text]', controlQuestion).each(function(i) { controlTotal = Number(controlTotal) + Number($(this).val()); }); $('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(controlTotal - sumTotal); $('span.dynamic_sum span', thisQuestion).text(sumTotal); $('span.dynamic_sum', thisQuestion).removeClass('good error'); if(answered > 0 && sumTotal == controlTotal) { $('span.dynamic_sum', thisQuestion).addClass('good'); } else if(answered > 0) { $('span.dynamic_sum', thisQuestion).addClass('error'); } } </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 3 months ago by tpartner.
The topic has been locked.
- slaugh
- Topic Author
- Offline
- New Member
Less
More
- Posts: 18
- Thank you received: 0
9 years 3 months ago #114809
by slaugh
Replied by slaugh on topic Equal sum value does not render the question unacceptable
It doesn't seem to work. May be I completed the code wrong...
It still prevents the participant to go to the next page even if the totals don't correspond.
It still prevents the participant to go to the next page even if the totals don't correspond.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify the elements var PROVSAL= $('#question{13560}'); var NBEMPLOI= PROVSAL.prevAll('.numeric-multi:eq(0)'); var inputs = $('input[type=text]', PROVSAL).add('input[type=text]', NBEMPLOI); // Insert the "totals" elements var totalvalue_13558= '<li class="multiplenumerichelp help-item">\ <span class="label">Restant: </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', PROVSAL).append(totalvalue_13560); // A listener on the inputs $(inputs).bind('change keyup', function(e) { handleInputs(PROVSAL, NBEMPLOI); }); $(inputs).bind('paste', function(e) { setTimeout(function () { handleInputs(PROVSAL, NBEMPLOI); }, 100); }); // Initialize sum values handleInputs(PROVSAL); }); // A function to calculate totals in a multiple numeric function handleInputs(PROVSAL, NBEMPLOI) { var PROVSAL= PROVSAL; var NBEMPLOI = NBEMPLOI; var controlTotal = 0; var answered = 0; var sumTotal = 0; $('input[type=text]', NBEMPLOI).each(function(i) { controlTotal = Number(controlTotal) + Number($(this).val()); }); $('input[type=text]', PROVSAL).each(function(i) { sumTotal = Number(sumTotal) + Number($(this).val()); if($(this).val() != '') { answered = Number(answered) + 1; } }); $('span.dynamic_remaining span', PROVSAL).text(controlTotal - sumTotal); $('span.dynamic_sum span', PROVSAL).text(sumTotal); $('span.dynamic_sum', PROVSAL).removeClass('good error'); if(answered > 0 && sumTotal == controlTotal) { $('span.dynamic_sum', PROVSAL).addClass('good'); } else if(answered > 0) { $('span.dynamic_sum', PROVSAL).addClass('error'); } </script>D’o&ugrave; proviennent vos salari&eacute;s permanents et saisonniers? <p> </p> <p> <span style="font-size:11px;"><em>Veuillez inscrire le nombre de salari&eacute;s pour chacune des r&eacute;ponses correspondant &agrave; votre situation.</em></span></p>
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
9 years 3 months ago #114810
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Equal sum value does not render the question unacceptable
Did you remove all of the other restrictions from the questions?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- slaugh
- Topic Author
- Offline
- New Member
Less
More
- Posts: 18
- Thank you received: 0
9 years 3 months ago #114811
by slaugh
Replied by slaugh on topic Equal sum value does not render the question unacceptable
When I remove all the other restrictions...total doesnt show at all.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
9 years 3 months ago #114814
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Equal sum value does not render the question unacceptable
Here is a working sample survey:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.
- slaugh
- Topic Author
- Offline
- New Member
Less
More
- Posts: 18
- Thank you received: 0
7 years 5 months ago #143133
by slaugh
Replied by slaugh on topic Equal sum value does not render the question unacceptable
I am trying to use the code you gave me a year ago for a new survey.
However, it doesn't seem to work.
I am working with LS Version 2.52+160920 and the default theme.
Here a link to the survey:
It is for the 6th question: Quelle part de votre chiffre d’affaires provient de chacun de ces canaux de mise en marché ?
The total should be 100 % but I don't want to prevent participant from filling the survey if the total is not 100%.
Thank you!
Sophie
However, it doesn't seem to work.
I am working with LS Version 2.52+160920 and the default theme.
Here a link to the survey:
It is for the 6th question: Quelle part de votre chiffre d’affaires provient de chacun de ces canaux de mise en marché ?
The total should be 100 % but I don't want to prevent participant from filling the survey if the total is not 100%.
Thank you!
Sophie
The topic has been locked.
- slaugh
- Topic Author
- Offline
- New Member
Less
More
- Posts: 18
- Thank you received: 0
7 years 5 months ago #143134
by slaugh
Replied by slaugh on topic Equal sum value does not render the question unacceptable
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>
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>
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
7 years 5 months ago #143142
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Equal sum value does not render the question unacceptable
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).
Code:
<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:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.