I'd like to reset the user input of radio buttons from outside the question. Based on the examples I found (https://www.qualtrics.com/community/discussion/1387/deselecting-a-radio-button) I though it would work if I just reference the other question with its QID in Qualtrics.SurveyEngine.registry[qid].setChoiceValue(5, 1, false). However it never works. So I do I properly reference another question?
The reset function looks like this.
```javascript
function Reset() {
$(questionid="QID2").hide();
for (var i = 1; i < 4; i++) {
$(questionid="QID2").setChoiceValue(i, false);
}
}
```
QID2 is the question I want to modify. The $(questionid="QID2").hide(); by it self works total fine. Only the .setChoiceValue doesn't work
Page 1 / 1
`$(questionid="QID2")` finds the div with the id of QID2. That is not the same thing as the question object (i.e., the "this" in this.setChoiceValue) .
Thanks for the fast reply, Tom. How would I properly reference the question object to execute setChoiceValue? I guess I need to use something like:
questionId = ????
Qualtrics.SurveyEngine.registry[questionId].setChoiceValue(i, false);
So far all approaches to assign the questionId of the other question haven't worked. Can you help?
questionId = ????
Qualtrics.SurveyEngine.registry[questionId].setChoiceValue(i, false);
So far all approaches to assign the questionId of the other question haven't worked. Can you help?
As far as I can tell, the question object (i.e. registry) isn't accessible from another question. Therefore, you can't apply setChoiceValue to a different question. You can do it directly through the DOM:
```
jQuery("#QID2 input").prop("checked", false);
```
```
jQuery("#QID2 input").prop("checked", false);
```
Unfortunately this solution is not working either. I tried all combinations but no success. I kept getting all kinds of errors.
> @DRSK said:
> Unfortunately this solution is not working either. I tried all combinations but no success. I kept getting all kinds of errors.
Please post your code.
> Unfortunately this solution is not working either. I tried all combinations but no success. I kept getting all kinds of errors.
Please post your code.
The code looks like this. What I try to do, is show and hide question QID2 and QID32 based on the selection of choices of the questions with the Javascript. In addition, I want to make sure that all selections are reset when hiding it. It won't work with display logic as I have quotas on the choices. I thought this is an easy thing but I already sitting since to days on it.
```javascript
Qualtrics.SurveyEngine.addOnload(function()
{
Reset();
this.questionclick = function(event,element){
Reset();
if (event.target.value == 1) {
$(questionid="QID2").show();
}
if (event.target.value == 2) {
$(questionid="QID32").show();
}
}
});
function Reset() {
$("QID2 input").each(function(i){
this.prop("checked", false);
});
$(questionid="QID2").hide();
$(questionid="QID32").hide();
}
```
```javascript
Qualtrics.SurveyEngine.addOnload(function()
{
Reset();
this.questionclick = function(event,element){
Reset();
if (event.target.value == 1) {
$(questionid="QID2").show();
}
if (event.target.value == 2) {
$(questionid="QID32").show();
}
}
});
function Reset() {
$("QID2 input").each(function(i){
this.prop("checked", false);
});
$(questionid="QID2").hide();
$(questionid="QID32").hide();
}
```
Replace $ with jQuery. $ in Qualtrics refers to prototypejs.
Thanks for the info. I now get the code running without errors. But it still doesn't deselect the radio buttons. I also attach the project as I'm totally out of ideas to fix this.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.