display message on radio click-javascript | XM Community
Skip to main content
Hello-Rather than using display logic, I'd like to show a specific message when any response is given on a multiple choice question.
Hi @profjm,

I think you should be more specific in defining your problem. From your current formulation, it is not clear what exactly you want to do. Should the message appear when the user clicks on a particular choice or when the user clicks the next button or elsewhen? Should the message appear in a pop-up box, on the page with the question or the next page? And why don't you want to use display logic? It might be simpler than implementing a JavaScript code.
Hello-

Apologies for the lack of clarity. I would like to have the information presented on the same page. A pop-up box would work, but it isn't necessary.



Let's say I had a multiple choice question with 1-5 as possible answers. The person selects a single answer. Regardless of whether the person clicked 1, 2 ,3 4, or 5, I would like a message to appear that indicates that the correct answer is a specific number, let's say 2.



The respondents will be practicing a problem-solving task, and I want them to get feedback along the way. There are 80 problems, so the answers vary depending on the problem.



Display logic is problematic for a number of reasons, based on the task. We are using it in other parts of the experiment.



Thank you-
Hi @profjm,

that's a much better explanation. What about something like this:



Put this script into the header of your survey.



<script>

function display_correct(Q, n ) {

Q.questionclick = function(event, element) {

if(element.type == "radio") {

alert("The correct answer is " + n);

}

}

}

</script>



You'll be able to access the function from any part of your survey.

You'll run this function like this:



Qualtrics.SurveyEngine.addOnload(function()

{

display_correct(this, 5);

});



In there is just one question on the page and you'd prefer to automatically proceed to the next question after the respondent closes the error message, add the following line to the function exactly bellow the `alert` function: `this.clickNextButton();`. It is also a simple way how to prevent respondets from modifying their original answer.
Worked great! Thanks for the help.
I have a similar need for a pop up message to appear when a particular radio button choice is selected. I'm not a coder so I'm not sure how to manipulate Qualtrics to make such a thing possible. Any help would be appreciated.

Hey all! I plan to do something similar like this. What if you wanted a message to pop-up when a certain response is selected, what would the code look like for this? fleb do you have any suggestions for the code? I'm also new to using javascript


Leave a Reply