Please help us help you and fill where relevant:
Your LimeSurvey version: [url=https://10.1.2.90:81/LimeSurveyMaster/index.php/questionAdministration/view?surveyid=423552&gid=1186&qid=16902#modalSystemInformation]6.16.10+260223[/url]
Own server or LimeSurvey hosting: Own server
Survey theme/template: fruity_twentythree
==================
I was encountering a problem of implementing exclusive answer option for my multiple option array.
I have actually found a solution for this without validation so that users have a better experience.
Would like to share it here if anyone else encountered the same problem or me or willing to further improve upon it.
This question requires "Array (Numbers)" with Checkbox layout turn ON.
Add the following script and change the variables for
- arrBatteryQuestion' as your code for battery questions
- arrValueAnswerCode' as your answer code (Do not include exclusive code)
- exclusiveCode the answer code for the exclusive option
$(document).ready(function () {
//Update here
const arrBatteryQuestion = ["1", "2", "3","4"]//Y-Scale
const arrValueAnswerCode = ["A", "B", "C"]//X-Scale (Do not include exclusive code)
const exclusiveCode = "N"
//When exclusive is click
for (let i = 0; i < arrBatteryQuestion.length; i++) {
let exclusivecheckbox = ("#cbox{SGQ}" + arrBatteryQuestion
+ "_" + exclusiveCode)
$(exclusivecheckbox).on("change", function () {
if (this.checked) {
for (let j = 0; j < arrValueAnswerCode.length; j++) {
let rowcheckbox = "#cbox{SGQ}" + arrBatteryQuestion + "_" + arrValueAnswerCode[j]
let answer= "#answer{SGQ}" + arrBatteryQuestion + "_" + arrValueAnswerCode[j]
$(rowcheckbox).prop("checked", false)
$(answer).val("")
}
}
});
}
//When non exclusive is click
for (let i = 0; i < arrBatteryQuestion.length; i++) {
let exclusivecheckbox = ("#cbox{SGQ}" + arrBatteryQuestion + "_" + exclusiveCode)
for (let j = 0; j < arrValueAnswerCode.length; j++) {
let answerCheckbox= ("#cbox{SGQ}" + arrBatteryQuestion + "_" + arrValueAnswerCode[j])
$(answerCheckbox).on("change",function(){
if (this.checked){
let answer= "#answer{SGQ}" + arrBatteryQuestion + "_" + exclusiveCode
$(exclusivecheckbox).prop("checked", false)
$(answer).val("")
}
});
}
}
});