How to get object of another question at the same page? | XM Community
Solved

How to get object of another question at the same page?

  • 15 May 2019
  • 1 reply
  • 30 views

Userlevel 5
Badge +6
  • Level 3 ●●●
  • 197 replies
I'm using following code to get actual choice for multiple choice question:

var selectedRecode;
this.questionclick = function(event, element) {
if(element.type == "radio")
{ selectedRecode = this.getChoiceRecodeValue(this.getSelectedChoices());
alert(selectedRecode);}}

It works fine now, however I'd like to place this code to another question on the same page while the code will be still related to the original question. Therefore I want to put the question object into a variable and replace `this` in code by this variable. Unfortunately I haven't found out how to get the question object. I could probably send my recorde to embedded data each time, but I think there must be some way how to get the object of the previous question...

I've tried following modification of my original code. There was no error, but nothing happened when I clicked on a choice.

var Q = jQuery( "#QID460" );
var selectedRecode;

Q.questionclick = function(event, element) {
if(element.type == "radio")
{ selectedRecode = Q.getChoiceRecodeValue(Q.getSelectedChoices());
alert(selectedRecode);}}

Thanks for any ideas!
icon

Best answer by fleb 15 May 2019, 23:14

View original

1 reply

Userlevel 5
Badge +6
Finally, I figured out how to do this without moving the code. I needed to hide or display following question based on the choice which is currently checked.
I used this code:

Qualtrics.SurveyEngine.addOnload(function()
{
var nextQ = document.getElementById("QID1033");
var selectedRecode;

this.questionclick = function(event, element) {
if(element.type == "radio")
{ selectedRecode = this.getChoiceRecodeValue(this.getSelectedChoices());
if(selectedRecode == 1) {nextQ.style.display = "block";}
else{nextQ.style.display = "none";}}}
});

Leave a Reply