Check out the LimeSurvey source code on GitHub!

change onclick attribute

More
5 years 6 months ago - 5 years 6 months ago #63767 by madopr
Well, what I need to do is this:
I have a multiple-choice question. Options are like this:
-OptionA
-OptionB
-OptionC
-No options
What i want is to uncheck the other optios when you check last option (and to uncheck this last option if one of the others is checked). I thought that could be done changing the onclick function of each checkbox; but I haven't managed to do it.

Another thing: I needed to filter the answers of an array type question depending on the answers of another question; I know how to do this if questions are in different sections; but not if they're in the same. I suppouse the solution for both problems should be similar.


[edit]
Ok, I think I'm near the solution for my first problem. I managed to change the onclick attribute for the checkboxes; but can't uncheck the other ones.
function deselecNingunaNoExisten()
{
	$('answer49192X181X2261r1').attr('checked', false);
	$('answer49192X181X2261r7').attr('checked', false);
}
 
function deselecResto(menos_esta)
{
	for (var i=1; i<=8; i++){
		if (i!=menos_esta){
			$('answer49192X181X2261r'+i).attr('checked', false);
		}
	}
}
 
jQuery(document).ready(
function()
{
	alert('SintaxisOK');
	for (var i=1; i<=8; i++){
		if (i==1||i==7){
			$('#answer49192X181X2261r'+i).click(function (event)
			{ 
				// The original functions of the click event
				cancelBubbleThis(event);
				checkconditions(this.value, this.name, this.type);
 
				if ($('#answer49192X181X2261r'+i).attr('checked') == true){
					deselecResto(i);
				}
			});
		} else{
			$('#answer49192X181X2261r'+i).click(function (event)
			{ 
				// The original functions of the click event
				cancelBubbleThis(event);
				checkconditions(this.value, this.name, this.type);
 
				if ($('#answer49192X181X2261r'+i).attr('checked') == true){
					deselecNingunaNoExisten();
				}
			});
		}
	}
});

what I wan't to do exactly is to uncheck all the other options when I check option 1 or 7 and uncheck options 1 and 7 when I check one of the others.

I got it!
<script type="text/javascript" charset="utf-8">
 
function deselecNingunaNoExisten()
{
	$('#answer49192X181X2261r1').attr('checked', false);
	$('#answer49192X181X2261r7').attr('checked', false);
}
 
function deselecRestoMenos1()
{
	$('#answer49192X181X2261r2').attr('checked', false);
	$('#answer49192X181X2261r3').attr('checked', false);
	$('#answer49192X181X2261r4').attr('checked', false);
	$('#answer49192X181X2261r5').attr('checked', false);
	$('#answer49192X181X2261r6').attr('checked', false);
	$('#answer49192X181X2261r7').attr('checked', false);
	$('#answer49192X181X2261r8').attr('checked', false);
}
 
function deselecRestoMenos7()
{
	$('#answer49192X181X2261r1').attr('checked', false);
	$('#answer49192X181X2261r2').attr('checked', false);
	$('#answer49192X181X2261r3').attr('checked', false);
	$('#answer49192X181X2261r4').attr('checked', false);
	$('#answer49192X181X2261r5').attr('checked', false);
	$('#answer49192X181X2261r6').attr('checked', false);
	$('#answer49192X181X2261r8').attr('checked', false);
}
 
jQuery(document).ready(
function()
{
	$('#answer49192X181X2261r1').click(function (event)
		{ 
			// The original functions of the click event
			cancelBubbleThis(event);
			deselecRestoMenos1();
			checkconditions(this.value, this.name, this.type);
		});
	$('#answer49192X181X2261r2').click(function (event)
		{ 
			// The original functions of the click event
			cancelBubbleThis(event);
			deselecNingunaNoExisten()
			checkconditions(this.value, this.name, this.type);
		});
	$('#answer49192X181X2261r3').click(function (event)
		{ 
			// The original functions of the click event
			cancelBubbleThis(event);
			deselecNingunaNoExisten()
			checkconditions(this.value, this.name, this.type);
		});
	$('#answer49192X181X2261r4').click(function (event)
		{ 
			// The original functions of the click event
			cancelBubbleThis(event);
			deselecNingunaNoExisten()
			checkconditions(this.value, this.name, this.type);
		});
	$('#answer49192X181X2261r5').click(function (event)
		{ 
			// The original functions of the click event
			cancelBubbleThis(event);
			deselecNingunaNoExisten()
			checkconditions(this.value, this.name, this.type);
		});
	$('#answer49192X181X2261r6').click(function (event)
		{ 
			// The original functions of the click event
			cancelBubbleThis(event);
			deselecNingunaNoExisten()
			checkconditions(this.value, this.name, this.type);
		});
	$('#answer49192X181X2261r7').click(function (event)
		{ 
			// The original functions of the click event
			cancelBubbleThis(event);
			deselecRestoMenos7();
			checkconditions(this.value, this.name, this.type);
		});
	$('#answer49192X181X2261r8').click(function (event)
		{ 
			// The original functions of the click event
			cancelBubbleThis(event);
			deselecNingunaNoExisten()
			checkconditions(this.value, this.name, this.type);
		});
});
 
</script>
Last Edit: 5 years 6 months ago by madopr.

Please Log in to join the conversation.

More
5 years 6 months ago - 5 years 6 months ago #63836 by tpartner
1) Why not use the "Exclusive option" advanced setting?[attachment:1]Capture.JPG[/attachment]

2) Array filter should work on the same page.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last Edit: 5 years 6 months ago by tpartner.

Please Log in to join the conversation.

More
5 years 5 months ago #63894 by madopr
That works better. Thanks!

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form