- Posts: 46
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Array text with sum Total for selected row and column .
- jerryd
- Topic Author
- Offline
- Senior Member
Less
More
8 years 4 months ago #129070
by jerryd
Thanks alot
jerryd
Array text with sum Total for selected row and column . was created by jerryd
Hi !
I am trying to make survey form that can calculate Total sum for selected row and column but i have different formats for my questions drop down and number so i can't get the total for only #male and #female and also grand total because i don't have valid intre could any one help me please ?
Thank you.
I am trying to make survey form that can calculate Total sum for selected row and column but i have different formats for my questions drop down and number so i can't get the total for only #male and #female and also grand total because i don't have valid intre could any one help me please ?
Thank you.
Thanks alot
jerryd
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
8 years 4 months ago #129082
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 Array text with sum Total for selected row and column .
Can you attach a small sample survey containing only that question?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- jerryd
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 46
- Thank you received: 0
8 years 4 months ago #129085
by jerryd
Thanks alot
jerryd
Replied by jerryd on topic Array text with sum Total for selected row and column .
ok
Thanks alot
jerryd
The topic has been locked.
- jerryd
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 46
- Thank you received: 0
8 years 4 months ago #129086
by jerryd
Thanks alot
jerryd
Replied by jerryd on topic Array text with sum Total for selected row and column .
Thanks alot
jerryd
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
8 years 4 months ago #129096
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 Array text with sum Total for selected row and column .
Despite the fact that it has a .lss extension, that appears to be a question export, not a survey export. Can you provide a survey export containing only that question?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- jerryd
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 46
- Thank you received: 0
8 years 4 months ago #129099
by jerryd
Thanks alot
jerryd
Replied by jerryd on topic Array text with sum Total for selected row and column .
Thanks alot
jerryd
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
8 years 4 months ago #129104
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 Array text with sum Total for selected row and column .
Well, it gets a little complicated because you are already using the
Variable Length Array workaround
.
You'll need to...
1) Add a new column and a new row to the array question for the totals.
2) Replace the Variable Length Array workaround with something like this:
A modified working survey attached:
You'll need to...
1) Add a new column and a new row to the array question for the totals.
2) Replace the Variable Length Array workaround with something like this:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify this question var thisQuestion = $('#question{QID}'); // Assign some classes and attributes thisQuestion.addClass('variable-length-text-array'); $('table.subquestions-list tr', thisQuestion).each(function(i){ $('> *', this).each(function(i){ $(this).addClass('column-'+i+''); $(this).attr('data-column', i); }); }); $('table.subquestions-list tr.subquestion-list td.column-4', thisQuestion).addClass('count female'); $('table.subquestions-list tr.subquestion-list td.column-5', thisQuestion).addClass('count male'); $('table.subquestions-list tr.subquestion-list td:last-child', thisQuestion).addClass('total row'); $('table.subquestions-list tr.subquestion-list:last', thisQuestion).addClass('totals'); // Insert some styles $('<style type="text/css">\ .hidden {\ display: none !important;\ visibility: hidden !important;\ }\ .expandable-control:disabled {\ opacity: 0.3;\ }\ </style>').appendTo('head'); // Insert the controls $('table.subquestions-list', thisQuestion).after('<div class="expandable-controls-wrapper">\ <button type="button" class="expandable-control remove">-</button>\ <button type="button" class="expandable-control add">+</button>\ </div>'); // Click events $('.expandable-control.add', thisQuestion).click(function (event) { $('tr.subquestion-list.hidden:first', thisQuestion).removeClass('hidden').addClass('shown'); handleArrayControls(); $('.expandable-control', thisQuestion).blur(); }); $('.expandable-control.remove', thisQuestion).click(function (event) { $('tr.subquestion-list.shown:last', thisQuestion).removeClass('shown').addClass('hidden'); clearRows(); handleArrayControls(); $('.expandable-control', thisQuestion).blur(); }); function handleArrayControls() { $('.expandable-control.remove', thisQuestion).prop('disabled', true); if($('tr.subquestion-list.dynamic:visible', thisQuestion).length > 1) { $('.expandable-control.remove', thisQuestion).prop('disabled', false); } $('.expandable-control.add', thisQuestion).prop('disabled', false); if($('tr.subquestion-list.dynamic:visible', thisQuestion).length == $('tr.subquestion-list', thisQuestion).length) { $('.expandable-control.add', thisQuestion).prop('disabled', true); } } function clearRows() { $('tr.subquestion-list.hidden input:text, tr.subquestion-list.hidden select', thisQuestion).val(''); columnTotals($('td.count.female:first')); columnTotals($('td.count.male:first')); } // Initially shown rows $('tr.subquestion-list:eq(0)', thisQuestion).addClass('dynamic shown'); $('tr.subquestion-list:gt(0):not(:last)', thisQuestion).addClass('dynamic hidden'); $('tr.subquestion-list.dynamic td:not(.total.row) input:text', thisQuestion).filter(function () {return !!this.value;}).closest('tr.subquestion-list').addClass('answered-row'); var thisQTable = $('table.subquestions-list', thisQuestion); var thisQRows = $('.answered-row', thisQuestion); var lastAnsweredRow = $('.answered-row:last', thisQuestion); var lastAnsweredIndex = $('tr.subquestion-list', thisQTable).index(lastAnsweredRow); $('tr.subquestion-list:lt('+(lastAnsweredIndex+1)+')', thisQuestion).removeClass('hidden').addClass('shown'); handleArrayControls(); // Readonly for totals $('table.subquestions-list td.total input[type="text"], table.subquestions-list tr.totals input[type="text"]', thisQuestion).prop('readonly', true); // Clean up the totals row $('tr.subquestion-list.totals td:not(.count):not(.total) input[type="text"]').val('N/A').hide(); // Initial totals $('td.total.row input[type="text"], tr.subquestion-list.totals td.count input[type="text"]').each(function(i) { if($(this).val() == '') { $(this).val(0); } }); // Listener on the count inputs $('table.subquestions-list td.count input[type="text"]', thisQuestion).on('change keyup', function(e) { // Row total var thisRow = $(this).closest('tr.subquestion-list'); var thisCountFemale = Number($('td.count.female input[type="text"]', thisRow).val()); if(isNaN(thisCountFemale)) { thisCountFemale = 0; } var thisCountMale = Number($('td.count.male input[type="text"]', thisRow).val()); if(isNaN(thisCountMale)) { thisCountMale = 0; } $('td.total input[type="text"]', thisRow).val(thisCountFemale + thisCountMale); // Column total columnTotals(this); }); function columnTotals(el) { var thisColumn = $(el).closest('td').attr('data-column'); var colTotal = 0; $('tr.subquestion-list:not(.totals) td[data-column="'+thisColumn+'"] input[type="text"]').each(function(i) { var thisVal = Number($(this).val()); if(!isNaN(thisVal)) { colTotal = colTotal + thisVal; } }); $('tr.subquestion-list.totals td[data-column="'+thisColumn+'"] input[type="text"]').val(colTotal); $('tr.totals td.total input[type="text"]').val(Number($('tr.totals td.count.female input[type="text"]').val())+Number($('tr.totals td.count.male input[type="text"]').val())); } }); </script>
A modified working survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: delarammahdaviii
The topic has been locked.
- jerryd
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 46
- Thank you received: 0
8 years 4 months ago #129134
by jerryd
Thanks alot
jerryd
Replied by jerryd on topic Array text with sum Total for selected row and column .
Thanks a lot for your help! it is really helpfull but i have also other problem i am using variable length array and when the user print it shows the hidden questions and also when i try to put some validation only for #Female & #Male to accept only number it accept for the whole question type so tpartner could you help me please.
Thank you!
Thank you!
Thanks alot
jerryd
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
8 years 4 months ago #129140
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 Array text with sum Total for selected row and column .
1) The variable length array workaround will not work with printing.
2) I suggest putting a mask on those inputs - manual.limesurvey.org/Workarounds:_Manip...ipt#Text_input_masks
2) I suggest putting a mask on those inputs - manual.limesurvey.org/Workarounds:_Manip...ipt#Text_input_masks
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: mikezhangsky, jerryd
The topic has been locked.
- jerryd
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 46
- Thank you received: 0
8 years 4 months ago #129142
by jerryd
Thanks alot
jerryd
Replied by jerryd on topic Array text with sum Total for selected row and column .
Thanks tpartner!
Thanks alot
jerryd
The topic has been locked.