Welcome, Guest
Username: Password: Remember me

TOPIC: change onclick attribute

change onclick attribute 2 years 8 months ago #63767

  • madopr
  • madopr's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
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: 2 years 8 months ago by madopr.
The administrator has disabled public write access.

Re: change onclick attribute 2 years 8 months ago #63836

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
1) Why not use the "Exclusive option" advanced setting?[attachment:1]Capture.JPG[/attachment]

2) Array filter should work on the same page.
Attachments:
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: 2 years 8 months ago by tpartner.
The administrator has disabled public write access.

Re: change onclick attribute 2 years 8 months ago #63894

  • madopr
  • madopr's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
That works better. Thanks!
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.127 seconds
Donation Image