display message on radio click-javascript

profjmprofjm Community Member Qubie ✭

display message on radio click-javascript

Hello-Rather than using display logic, I'd like to show a specific message when any response is given on a multiple choice question.

Tagged:

Best Answer

  • flebfleb Czech Republic Sage ✭✭✭
    Accepted Answer

    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.

Answers

  • flebfleb Czech RepublicCommunity Member Sage ✭✭✭
    edited February 14

    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.

  • profjmprofjm Community Member Qubie ✭

    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-

  • profjmprofjm Community Member Qubie ✭

    Worked great! Thanks for the help.

  • Girl_Scout_8Girl_Scout_8 San Diego, CACommunity Member Qubie ✭

    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.

Sign In to Comment