- Posts: 49
- Thank you received: 1
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
- Topic Author
- Offline
- Senior Member
Less
More
3 years 8 months ago #202111
by tpervaiz
Disable radio button after selection as well as highlight the answer in color was created 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
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:
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12789
- Thank you received: 3940
3 years 8 months ago #202188
by Joffm
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','')}
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Disable radio button after selection as well as highlight the answer in color
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','')}
No, but you may trigger the next-button "on click".1: Disable radio answers after user selection one of the answer so he cannot select again any answer
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13935
- Thank you received: 2551
3 years 8 months ago #202197
by DenisChenu
Untested :
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.
Replied by DenisChenu on topic Disable radio button after selection as well as highlight the answer in color
I think you canJoffm wrote:
No, but you may trigger the next-button "on click".1: Disable radio answers after user selection one of the answer so he cannot select again any answer
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
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
3 years 8 months ago - 3 years 8 months ago #202199
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Disable radio button after selection as well as highlight the answer in color
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.