Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

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

  • tpervaiz
  • tpervaiz's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 8 months 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
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months 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".
Code:
<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
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months 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".
Code:
<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 :
Code:
<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.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago - 3 years 8 months ago #202199 by tpartner
1: Try this (untested as I am responding via phone). Make sure you test the data after implementing.

Code:
<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.
Last edit: 3 years 8 months ago by tpartner.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose