- Posts: 1
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Assigning default values to numerical array in subquestions
- wstahl09
- Topic Author
- Offline
- New Member
Less
More
9 years 7 months ago #111067
by wstahl09
Assigning default values to numerical array in subquestions was created by wstahl09
Hello,
I have a mandatory question that prompts the user to indicate the days and hours since an event, which is saved into a numerical array. I was wondering if there was anyway to set a default value of 0 to both days and hours, and if not how I could go about doing so with javascript.
Thanks!
I have a mandatory question that prompts the user to indicate the days and hours since an event, which is saved into a numerical array. I was wondering if there was anyway to set a default value of 0 to both days and hours, and if not how I could go about doing so with javascript.
Thanks!
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3691
9 years 7 months ago - 9 years 7 months ago #111074
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 Assigning default values to numerical array in subquestions
Are you using an
Array (Numbers)(Checkbox)
or
Array (Texts)(Numbers only)
question type?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 7 months ago by tpartner.
The topic has been locked.
- MVT
- Offline
- Junior Member
Less
More
- Posts: 24
- Thank you received: 0
9 years 4 months ago #113976
by MVT
Replied by MVT on topic Assigning default values to numerical array in subquestions
Hi,
I tried a tip/workaround find here but...
I've an array of numbers with the checkbox option.
I've added this code (found in the workaround page) :
It works well but...
My question is mandatory. The values (boexe checked) do not appear to be taken into account.
Do I miss something ?
For the moment, I put my question "optional..."
Is it possible (for check boxes) to check on column for all the values in that column ?
Thanks
I tried a tip/workaround find here but...
I've an array of numbers with the checkbox option.
I've added this code (found in the workaround page) :
Code:
<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.checkbox[checked=true]', this).length == 0) { $('input.checkbox:eq(' + checkedCol + ')', this).attr('checked', true); } }); } // Call the function with a question ID and column number checkedDefault(165, 1); }); </script>
It works well but...
My question is mandatory. The values (boexe checked) do not appear to be taken into account.
Do I miss something ?
For the moment, I put my question "optional..."
Is it possible (for check boxes) to check on column for all the values in that column ?
Thanks
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3691
9 years 4 months ago #113993
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 Assigning default values to numerical array in subquestions
Function updated for 2.05...
And I've updated the workaround page - manual.limesurvey.org/Workarounds:_Manip...s_in_array_questions
.
Code:
<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+' tr.subquestions-list').each(function(i) { if ($('input.checkbox:checked', this).length == 0) { $('input.checkbox:eq('+checkedCol+')', this).prop('checked', true); $('input.checkbox:eq('+checkedCol+')', this).parent().find('input[type="hidden"]').val(1); } }); } // Call the function with a question ID and column number checkedDefault(165, 1); }); </script>
And I've updated the workaround page - manual.limesurvey.org/Workarounds:_Manip...s_in_array_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.
- MVT
- Offline
- Junior Member
Less
More
- Posts: 24
- Thank you received: 0
9 years 4 months ago #113998
by MVT
Replied by MVT on topic Assigning default values to numerical array in subquestions
Thanks tpartner.
I'll test it today.
Is it possible in the same function (I suppose a part of code between <script> </script>) to uncheck the first column (NSP in French, NA or NO ? in English ?) if one or more options are checked on the same line?
If a user save his survey to complete it at another moment, are his answers saved and not "resetted" by this script?.
I suppose we can do something like a sum of all the columns (except the column passed by the parameter) in a line and check only if the sum = 0.
I'll try this if I find a few hours. I'm a very "newbee" in JS !
In the snippet, I've replaced input.radio bu input.checkbox (in the original release)
Regards
I'll test it today.
Is it possible in the same function (I suppose a part of code between <script> </script>) to uncheck the first column (NSP in French, NA or NO ? in English ?) if one or more options are checked on the same line?
If a user save his survey to complete it at another moment, are his answers saved and not "resetted" by this script?.
I suppose we can do something like a sum of all the columns (except the column passed by the parameter) in a line and check only if the sum = 0.
I'll try this if I find a few hours. I'm a very "newbee" in JS !
In the snippet, I've replaced input.radio bu input.checkbox (in the original release)
Regards
The topic has been locked.