Hiding specific checkboxes in multiple choice question

More
4 years 3 weeks ago - 4 years 3 weeks ago #119673 by marba
Hi!

I have a multiple options question in which I'm using some options as a category title. For that, I used the sub-options workaround, made the category titles checked by definition, and then hide those checkboxes, as they are not clickable-options.
To hide them, I wrote this on the question code:
<script charset="utf-8" type="text/javascript">      
   $(document).ready(function() {  
 
        $( 'input.checkbox', 'li.question-item:eq(0)' ).css ({                     
              'display': 'none' 
});
        $( 'input.checkbox', 'li.question-item:eq(5)' ).css ({                     
              'display': 'none' 
});
        $( 'input.checkbox', 'li.question-item:eq(10)' ).css ({                     
              'display': 'none' 
});
        $( 'input.checkbox', 'li.question-item:eq(15)' ).css ({                     
              'display': 'none' 
});
        $( 'input.checkbox', 'li.question-item:eq(19)' ).css ({                     
              'display': 'none' 
});
        $( 'input.checkbox', 'li.question-item:eq(23)' ).css ({                     
              'display': 'none' 
});
        $( 'input.checkbox', 'li.question-item:eq(29)' ).css ({                     
              'display': 'none' 
});
 
 
});
</script>





It works perfectly, but what is happening is that a previous answer of multiple choice is being affected by this and some checkboxes disappear!






How can I make this code affect only this question and its subquestions?




Thanks!
Attachments:
Last edit: 4 years 3 weeks ago by DenisChenu. Reason: Usage of code

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

LimeSurvey Partners
More
4 years 3 weeks ago #119685 by DenisChenu
You have to restrivt to THIS question:

$( 'input.checkbox', '#question{QID} li.question-item:eq(0)' ).css ({

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand .
An error happen ? Before make a new topic : remind the Debug mode .
The following user(s) said Thank You: marba

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

More
4 years 3 weeks ago #119724 by tpartner
I don't think you need to use scope here. Simple selectors should work.

<script charset="utf-8" type="text/javascript">      
	$(document).ready(function() {  
 
		$( '#question{QID} li.question-item:eq(0) input.checkbox').css ({                     
			'display': 'none' 
		});
		$( 'question{QID} li.question-item:eq(5) input.checkbox').css ({                     
			'display': 'none' 
		});
		$( 'question{QID} li.question-item:eq(10) input.checkbox').css ({                     
			'display': 'none' 
		});
		$( 'question{QID} li.question-item:eq(15) input.checkbox').css ({                     
			'display': 'none' 
		});
		$( 'question{QID} li.question-item:eq(19) input.checkbox').css ({                     
			'display': 'none' 
		});
		$( 'question{QID} li.question-item:eq(23) input.checkbox').css ({                     
			'display': 'none' 
		});
		$( 'question{QID} li.question-item:eq(29) input.checkbox').css ({                     
			'display': 'none' 
		});
	});
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
The following user(s) said Thank You: marba

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

More
4 years 3 weeks ago #119725 by marba
thank you both! I was going around different ways of referring to the question, and it seems it was never the right one! Still a lot to learn :laugh:
It's working now.

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

More
3 months 2 days ago #180721 by krosser

tpartner wrote: I don't think you need to use scope here. Simple selectors should work.

<script charset="utf-8" type="text/javascript">      
	$(document).ready(function() {  
 
		$( '#question{QID} li.question-item:eq(0) input.checkbox').css ({                     
			'display': 'none' 
		});
		$( 'question{QID} li.question-item:eq(5) input.checkbox').css ({                     
			'display': 'none' 
		});
		$( 'question{QID} li.question-item:eq(10) input.checkbox').css ({                     
			'display': 'none' 
		});
		$( 'question{QID} li.question-item:eq(15) input.checkbox').css ({                     
			'display': 'none' 
		});
		$( 'question{QID} li.question-item:eq(19) input.checkbox').css ({                     
			'display': 'none' 
		});
		$( 'question{QID} li.question-item:eq(23) input.checkbox').css ({                     
			'display': 'none' 
		});
		$( 'question{QID} li.question-item:eq(29) input.checkbox').css ({                     
			'display': 'none' 
		});
	});
</script>


Hi Tony,
Is there an update of this script for LS 3.15 and would it be different for the multiple-choice with comments?
I am trying to rewrite the "li.question-item:eq" and "input.checkbox" part, but to no avail.

I'm using the latest LS 3.17 hosted on LS servers, not installed locally.

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!