Disable radio button after selection as well as highlight the answer in color

More
1 month 1 week ago #202111 by tpervaiz
I am looking for 2 things

1: Disable radio answers after user selection one of the answer so he cannot select again any answer

2: Highlight correct answer in Green and wrong answer in Red. Wrong answer should show the correct answer aswell.

I have a code for point 2 however only issue I am facing is that if no selection is done...Its showing Red with correct answer
Attachments:

Please Log in to join the conversation.

LimeSurvey Partners
More
1 month 1 week ago #202188 by Joffm

Its showing Red with correct answer


This is because your equation is not correct.

{if (q4 == 'A2' , 'Correct' , 'Incorrect, Correct Answer is B')}
You see, if the answer is empty, it is NOT equal to "A2"; therefore it is a wrong answer.

You have to extend your equation to check that the answer is not empty.
Like
{if(is_empty(self),'', if(self!="A2",''+self.shown+' is not correct',''+self.shown+' is correct'))}

{if(!is_empty(self) and self!"A2",'The correct answer is: Answer 3','')}


1: Disable radio answers after user selection one of the answer so he cannot select again any answer

No, but you may trigger the next-button "on click".
<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function(){
 
		$('#question{QID} input:radio[id^="answer"]').on('click', function(e) {
			$('#ls-button-submit').trigger('click');
		});
	});
</script>


Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:

Please Log in to join the conversation.

More
1 month 1 week ago #202197 by DenisChenu

Joffm wrote:

1: Disable radio answers after user selection one of the answer so he cannot select again any answer

No, but you may trigger the next-button "on click".
<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function(){
 
		$('#question{QID} input:radio[id^="answer"]').on('click', function(e) {
			$('#ls-button-submit').trigger('click');
		});
	});
</script>


Joffm

I think you can ;)

Untested :
<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function(){
 
		$('#question{QID} input:radio[id^="answer"]').on('click', function(e) {
			$("input:radio[name='"+$(this).attr('name')+"']").not(this).prop(disabled',true);
		});
	});
</script>

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development . I don't answer to private message.

Please Log in to join the conversation.

More
1 month 1 week ago - 1 month 1 week ago #202199 by tpartner
1: Try this (untested as I am responding via phone). Make sure you test the data after implementing.

<script type="text/javascript" charset="utf-8">
	$(document).on('ready', function(){
 
		$('#question{QID} input:radio[id^="answer"]').on('click', function(e) {
			$('#question{QID} input:radio[id^="answer"]').not(this).prop('disabled' true);
		});
	});
</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
Last edit: 1 month 1 week ago by tpartner.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now