Default option for array by column

More
6 months 2 weeks ago #165161 by Matiasko
Matiasko created the topic: Default option for array by column
Hello :)

I would like to know how to make first option (Not applicable) in each column prefilled (default). I already know how to do it in standard array (by row) with the code below:
<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function(){
		// Identify the questions
		var qID = {QID};
		var q = $('#question'+qID);
 
		// Default answers
		$('table.subquestion-list tr.answers-list', q).each(function(i) {
			if($('input[type="radio"]:checked', this).length == 0) {
				$('input[type="radio"]:first', this).trigger('click');
			}
		});
    });
</script>
In addition, I would like to have radio button for first column (I) option 'Not applicable' disabled all the time (no default answer for this column).

My version of Lime: 3.3.1, survey attached.

Thank you in advance

P.S.
It would be helpful to have a page with 'Make default option for question type: xxx' with code for all questions that don't support 'Default answer' or to have it implemented inside LimeSurvey :)
Attachments:
The following user(s) said Thank You: szylkrecik

Please Log in or Create an account to join the conversation.

More
6 months 2 weeks ago #165164 by tpartner
tpartner replied the topic: Default option for array by column
This script should meet both of your requirements:

<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function(){
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Loop through first-row answers
		$('tr.answers-list:eq(0) input[type="radio"]', thisQuestion).each(function(i) {
 
			// Disable the first radio in the first column
			if(i == 0) {
				$(this).prop('disabled', true);
			}
			// Default answers
			else {
				var thisName = $(this).attr('name');
				if($('input[type="radio"][name="'+thisName+'"]:checked', thisQuestion).length == 0) {
					$(this).trigger('click');
				}
			}
		});
	});
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...3521.lss
File Size:19 KB

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: szylkrecik

Please Log in or Create an account to join the conversation.

More
6 months 1 week ago #165299 by Matiasko
Matiasko replied the topic: Default option for array by column
As always works great, thank you!

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!