Welcome to the LimeSurvey Community Forum

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

Multiple answer array with exclusive code

More
12 hours 36 minutes ago #274403 by ericlok
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
  1. arrBatteryQuestion' as your code for battery questions
  2. arrValueAnswerCode' as your answer code (Do not include exclusive code)
  3. 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("")
                }
            });
        }
    }
});
 

Please Log in to join the conversation.

More
5 hours 28 minutes ago - 5 hours 26 minutes ago #274405 by Joffm
Hi,

I was encountering a problem of implementing exclusive answer option for my multiple option array.


Which problem did you encounter, that you couldn't use the "old" workaround in the manual?
[url] www.limesurvey.org/manual/Workarounds:_M..._Excludes_All_Others [/url]

In my version 6.16.13. and in the Cloud version 6.17.4. the implementation for 3.x. works fine.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 5 hours 26 minutes ago by Joffm.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose