Welcome to the LimeSurvey Community Forum

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

check which answer (radio list) was checked and alert if answer code is wrong

  • elihaz
  • elihaz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 7 months ago #173104 by elihaz
Hi

I need that every time a user check a radio button from the list, the answer value (or even better answer code e.g A1)
will be copmared to the right answer, and alerted if wrong. tried this not working jquery:
Code:
 
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){
     var thisQuestion = $('#question{QID}');
        var q1Ans = '';
      if($('input.radio:checked', thisQuestion).length > 0) {
         q1Ans = $('input.radio:checked', thisQuestion).attr('value');
         if(q1Ans != "let's be friend") {
          alert("wrong!");
      }
 
 
    });
  });
</script>
 

Any Ideas? Tnx.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 7 months ago #173119 by tpartner
1) You will need to test the answer codes, not the answer text.

2) I see no listener on the radio buttons.

What Limesurvey version are you using?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 7 months ago #173128 by DenisChenu
And why not, in help for example :
{if(self.NAOK=="A1","","Error")}
Or use manual.limesurvey.org/Question_type_-_Li...28em_validation_q.29

Else : $('input.radio:checked', thisQuestion).attr('value') give the code, not the text …

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
5 years 7 months ago #173135 by tpartner
I wonder, why present a list-radio question with multiple answers if you won't allow wrong answers.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • elihaz
  • elihaz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 7 months ago #173136 by elihaz
The topic has been locked.
  • elihaz
  • elihaz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 7 months ago #173140 by elihaz
Hi
Thank you for helping.
1) yep... forgot the listener.
2) debugging> I think it's the "var thisQuestion = $('#question{QID}');"
the following code is working but the alert shows [object object]
Code:
 
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){
    $('#question{QID} input.radio').on('click', function(e){
       var thisQuestion = $('#question{QID}');
      alert(thisQuestion);  // [object Object]
 
 
    });
  });
</script>
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 7 months ago #173144 by DenisChenu
Did you read ?

Did you try to understand jquery ?

Else : $('input.radio:checked', thisQuestion).attr('value') give the code, not the text …


Then : if(q1Ans != "A1") {

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
5 years 7 months ago #173146 by tpartner
Try this (untested):

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){
    var correctCode = 'A1':
 
    $('#question{QID} input[type="radio"]').on('click', function(e){
       var thisVal = $(this).val();
 
      if(thisVal != correctCode) {
        alert('Wrong answer dummy!');  
      }
    });
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose