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

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

  • May 15, 2019
  • 1 reply
  • 70 views

fleb
Level 3 ●●●
Forum|alt.badge.img+6
  • Level 3 ●●●
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!

Best answer by fleb

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";}}} });

1 reply

fleb
Level 3 ●●●
Forum|alt.badge.img+6
  • Author
  • Level 3 ●●●
  • Answer
  • May 15, 2019
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";}}} });