Welcome, Guest
Username: Password: Remember me

TOPIC: Assigning default values to numerical array in subquestions

Assigning default values to numerical array in subquestions 3 months 4 weeks ago #111067

  • wstahl09
  • wstahl09's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 1
  • Karma: 0
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!
The administrator has disabled public write access.

Assigning default values to numerical array in subquestions 3 months 4 weeks ago #111074

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4356
  • Thank you received: 826
  • Karma: 381
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 3 months 4 weeks ago by tpartner.
The administrator has disabled public write access.

Assigning default values to numerical array in subquestions 3 weeks 1 day ago #113976

  • MVT
  • MVT's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 36
  • Karma: 0
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) :
<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 administrator has disabled public write access.

Assigning default values to numerical array in subquestions 3 weeks 1 day ago #113993

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4356
  • Thank you received: 826
  • Karma: 381
Function updated for 2.05...

<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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Assigning default values to numerical array in subquestions 3 weeks 1 day ago #113998

  • MVT
  • MVT's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 36
  • Karma: 0
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
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.174 seconds
Donation Image