- Posts: 166
- Thank you received: 26
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Restrict the answers to a Multiple Choice question with Exclusive Answer
- davebostockgmail
- Topic Author
- Offline
- Elite Member
Less
More
3 years 1 week ago #213709
by davebostockgmail
Restrict the answers to a Multiple Choice question with Exclusive Answer was created by davebostockgmail
I had a problem with a multiple choice question where the respondent HAD to choose their top 3 answers BUT the question had an exclusive option in the list.
After trying unsuccessfully to do this with the question validation, I still cannot get that to work for me I should look into it more, I came up with the following script that may be helpful to others in this situation
On a mandatory Multiple Choice question I used this...
// Stop the next button submitting the answers
$('#ls-button-submit').bind('click', function () {
//The answer code for the Exclusive Option
if ( !$("#answer172258X582X2244812").prop('checked')) {
// The count of required answers
if ($("input:checkbox:checked").length ! ) {
// The message that comes up on trying to submit the question if the Exclusive option is not selected or the number of answers is not the required count.
alert("Please select three messages.");
return false;
}
}
});
Hope this can help someone else
This works on Limesurvey 3.25
After trying unsuccessfully to do this with the question validation, I still cannot get that to work for me I should look into it more, I came up with the following script that may be helpful to others in this situation
On a mandatory Multiple Choice question I used this...
// Stop the next button submitting the answers
$('#ls-button-submit').bind('click', function () {
//The answer code for the Exclusive Option
if ( !$("#answer172258X582X2244812").prop('checked')) {
// The count of required answers
if ($("input:checkbox:checked").length ! ) {
// The message that comes up on trying to submit the question if the Exclusive option is not selected or the number of answers is not the required count.
alert("Please select three messages.");
return false;
}
}
});
Hope this can help someone else
This works on Limesurvey 3.25
The following user(s) said Thank You: tpartner
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13935
- Thank you received: 2551
3 years 1 week ago - 3 years 1 week ago #213721
by DenisChenu
(count(self.NAOK==1) and !is_empty(Q00_EXCLUDE.NAOK) )
OR
(count(self.NAOK=) and is_empty(Q00_EXCLUDE.NAOK) )
no ?
[EDIT] and with exclude option
!is_empty(Q00_EXCLUDE.NAOK) or count(self.NAOK) == 3
(sample survey)
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 Restrict the answers to a Multiple Choice question with Exclusive Answer
Without using included exclude, question code to Q00After trying unsuccessfully to do this with the question validation, I still cannot get that to work for me I should look into it more, I came up with the following script that may be helpful to others in this situation
(count(self.NAOK==1) and !is_empty(Q00_EXCLUDE.NAOK) )
OR
(count(self.NAOK=) and is_empty(Q00_EXCLUDE.NAOK) )
no ?
[EDIT] and with exclude option
!is_empty(Q00_EXCLUDE.NAOK) or count(self.NAOK) == 3
(sample survey)
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.
Attachments:
Last edit: 3 years 1 week ago by DenisChenu. Reason: [EDIT]
The following user(s) said Thank You: davebostockgmail
The topic has been locked.
- davebostockgmail
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 166
- Thank you received: 26
3 years 6 days ago #213790
by davebostockgmail
Replied by davebostockgmail on topic Restrict the answers to a Multiple Choice question with Exclusive Answer
Thanks Denis, I will experiment with the question validation some more as this seems simpler.
The topic has been locked.