- Posts: 3
- Thank you received: 0
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
- Topic Author
- Offline
- New Member
Less
More
5 years 7 months ago #173104
by elihaz
check which answer (radio list) was checked and alert if answer code is wrong was created 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:
Any Ideas? Tnx.
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10103
- Thank you received: 3593
5 years 7 months ago #173119
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 check which answer (radio list) was checked and alert if answer code is wrong
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?
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13633
- Thank you received: 2490
5 years 7 months ago #173128
by DenisChenu
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 check which answer (radio list) was checked and alert if answer code is wrong
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 …
{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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10103
- Thank you received: 3593
5 years 7 months ago #173135
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 check which answer (radio list) was checked and alert if answer code is wrong
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
5 years 7 months ago #173136
by elihaz
Replied by elihaz on topic check which answer (radio list) was checked and alert if answer code is wrong
2.5+ build 16037
The topic has been locked.
- elihaz
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
5 years 7 months ago #173140
by elihaz
Replied by elihaz on topic check which answer (radio list) was checked and alert if answer code is wrong
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]
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13633
- Thank you received: 2490
5 years 7 months ago #173144
by DenisChenu
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 check which answer (radio list) was checked and alert if answer code is wrong
Did you read ?
Did you try to understand jquery ?
Then : if(q1Ans != "A1") {
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10103
- Thank you received: 3593
5 years 7 months ago #173146
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 check which answer (radio list) was checked and alert if answer code is wrong
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.