Checkbox value in Javascript

Hello,
I would like to set up a single interactive exercise with a set of 3 or 4 True / False questions which would all be submitted at the same time and which would be correct only if all True/False questions composing the set are correct.
A multiple response layout works fine for this - but I was trying - and failing - to write a small Javascript snippet which when a True value is checked by a user its matching False value is unchecked and with versa.
I tried with “if(prez.object(‘T1’).checkbox = true)” but obviously this is not working.
Where can I get the checked value of the checkbox object?

or do you see a better way to approach this?

Best regards,
Michael

Hi Michael,

You can use checked method to check if a checkbox is checked or not:

if (prez.object('checkbox_name').checked()) {
    // it's checked
} else {
    // it's unchecked
}

But I’m not sure why you need the script? You can double-click checkboxes in the multiple response question to set the correct state.

Regards

Hi,
thanks.
I’m looking for it to change when the user checks the box in the HTML… e.g. if he checks true on line 1 it unchecks false on line 1 and if he checks false on line 2 it unchecks true on line 2.
But in fact I think it works find using change state:
I change the object state false to Normal when true is checked and vice versa - and repeat his for any line of true false.
Thanks,
Michael

Hi Michael,

Does it seem you are looking for the multiple questions in one slide like this?

If yes, please see the attached sample. MultipleQuestionsSample.approj (448 KB)
In this sample, I’m using variables and action condition to set up the Correct Feedback Layer only shows if users answer all questions correctly. You can customize it to fit your needs.

Regards,

Thanks a lot for sharing this.
Yes, this is the kind of thing I was looking for.
Best regards,
Michael

1 Like