this.getChoiceAnswerValue(); not a function??? | XM Community
Solved

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

  • 31 July 2019
  • 2 replies
  • 101 views

Userlevel 3
Badge +9
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?
icon

Best answer by zamechek 14 September 2022, 15:44

View original

2 replies

Userlevel 3
Badge +9

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.

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

});

Leave a Reply