this.getChoiceAnswerValue(); not a function??? | XM Community
Skip to main content
Solved

this.getChoiceAnswerValue(); not a function???


Forum|alt.badge.img+9
  • Level 2 ●●
  • 61 replies
I am playing around in prep for developing a soft-prompt in Qualtrics (because they do not have a feature for one) and I ran into a situation where the console is telling me 'this.getChoiceAnswerValue' is not a function. 1. I've hidden the 'NEXT' button and replaced it with a fake one 2. On click I am trying to have Qualtrics check answers on the question. 3. If the answer(s) are length of 0, flag the question as empty.) `Qualtrics.SurveyEngine.addOnReady(function() { /*Place your JavaScript here to run when the page is fully displayed*/ /*Create the fakeNext button, copy NextButton styling, and then hide the NextButton*/ jQuery("#NextButton").after("<button type='button' class='NextButton Button' id='fakeNext' value='NEXT' title='NEXT' aria-label='NEXT'>NEXT</button>"); jQuery('#fakeNext').copyCSS('#NextButton'); jQuery("#NextButton").hide(); var empty = 0; jQuery('#fakeNext').click(function(){ var answers = this.getChoiceAnswerValue(); console.log("Answers = " + answers); if(answers.length=0){ empty = 1; } else { empty = 0; } console.log("Empty flag = " + empty); }); });` Is it not possible to use this.getChoiceAnswerValue(); at this point? Do I have something silly hiding in there that's messing me up?

Best answer by zamechek

The value of this changes within the

click(function(){
function. So you need to do this.

var that = this;
jQuery('#fakeNext').click(function(){
var answers = that.getChoiceAnswerValue();
console.log("Answers = " + answers);
if(answers.length=0){
empty = 1;
} else {
empty = 0;
}
console.log("Empty flag = " + empty);

});

View original

2 replies

  • 1 reply
  • Answer
  • September 14, 2022

The value of this changes within the

click(function(){
function. So you need to do this.

var that = this;
jQuery('#fakeNext').click(function(){
var answers = that.getChoiceAnswerValue();
console.log("Answers = " + answers);
if(answers.length=0){
empty = 1;
} else {
empty = 0;
}
console.log("Empty flag = " + empty);

});


Forum|alt.badge.img+9
  • Author
  • Level 2 ●●
  • 61 replies
  • September 14, 2022

Thank you zamehcek ! I completely forgot about this question. I think I realized what had happened all those years ago because we did manage to get it working.
Flagging as correct answer in case anyone else comes across the silliness.


Leave a Reply