Solved
JS trigger next button and previous button through selected answer "yes" or "no"
Hello everyone,
I need to add a script at a "yes or no"-question. If a subject clicks yes, the next question should be shown. If a subject clicks no, it should return to the previous question. Both buttons, previous and next, should not be visible. They should just be triggered through yes and no. I can't make it work, I would be grateful for some help.
Thanks
I need to add a script at a "yes or no"-question. If a subject clicks yes, the next question should be shown. If a subject clicks no, it should return to the previous question. Both buttons, previous and next, should not be visible. They should just be triggered through yes and no. I can't make it work, I would be grateful for some help.
Thanks
Best answer by TomG
You need to use event handlers:
```
Qualtrics.SurveyEngine.addOnReady(function() {
var qobj = this;
jQuery("#Buttons").hide();
jQuery("#"+this.questionId+" input[choiceid=1]").click(function() { qobj.clickNextButton(); });
jQuery("#"+this.questionId+" input[choiceid=2]").click(function() { qobj.clickPreviousButton(); });
});
```
No need for an unload function.
EDIT: previous button id corrected.
View original```
Qualtrics.SurveyEngine.addOnReady(function() {
var qobj = this;
jQuery("#Buttons").hide();
jQuery("#"+this.questionId+" input[choiceid=1]").click(function() { qobj.clickNextButton(); });
jQuery("#"+this.questionId+" input[choiceid=2]").click(function() { qobj.clickPreviousButton(); });
});
```
No need for an unload function.
EDIT: previous button id corrected.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.