Buy Licenses Contact Support Login/Register
v 1.7.19
v 1.7.19
Overview Examples Docs Source Download

Review Quiz results

Use customer render and display mode to review a quiz results


                        
        
            Survey.StylesManager.applyTheme("modern");
        


            
                var json = {
  title: "American History",
  showProgressBar: "bottom",
  showTimerPanel: "top",
  maxTimeToFinishPage: 10,
  maxTimeToFinish: 25,
  firstPageIsStarted: true,
  startSurveyText: "Start Quiz",
  pages: [
    { questions: [ {type: "html", html: "You are about to start quiz by history. <br/>You have 10 seconds for every page and 25 seconds for the whole survey of 3 questions.<br/>Please click on <b>'Start Quiz'</b> button when you are ready." } ] },
    {
      questions: [
        {
          type: "radiogroup",
          name: "civilwar",
          title: "When was the Civil War?",
          choices: [ "1750-1800", "1800-1850", "1850-1900", "1900-1950", "after 1950" ],
          correctAnswer: "1850-1900"
        }
      ]
    },
    {
      questions: [
        {
          type: "radiogroup",
          name: "libertyordeath",
          title: "Who said 'Give me liberty or give me death?'",
          choicesOrder: "random",
          choices: [ "John Hancock", "James Madison", "Patrick Henry", "Samuel Adams" ],
          correctAnswer: "Patrick Henry"
        }
      ]
    },
    {
      maxTimeToFinish: 15,
      questions: [
        {
          type: "radiogroup",
          name: "magnacarta",
          title: "What is the Magna Carta?",
          choicesOrder: "random",
          choices: [ "The foundation of the British parliamentary system", "The Great Seal of the monarchs of England", "The French Declaration of the Rights of Man", "The charter signed by the Pilgrims on the Mayflower" ],
          correctAnswer: "The foundation of the British parliamentary system"
        }
      ]
    }
  ],
  completedHtml: "<h4>You have answered correctly <b>{correctedAnswers}</b> questions from <b>{questionCount}</b>.</h4>"
};

                window.survey = new Survey.Model(json);
            
        
            survey.onComplete.add(function(result) {
            document.querySelector('#surveyResult').textContent =
            "Result JSON:\n" + JSON.stringify(result.data, null, 3);
            });
        
survey.data = {civilwar: "1850-1900", libertyordeath: "Samuel Adams", magnacarta: "The foundation of the British parliamentary system"};

survey.mode = "display";
survey.questionsOnPageMode = "singlePage";
survey.showNavigationButtons = "none";
survey.showProgressBar = "off";
survey.showTimerPanel = "none";
survey.maxTimeToFinishPage = 0;
survey.maxTimeToFinish = 0;
survey
    .onAfterRenderQuestion
    .add(function (survey, options) {
        var span = document.createElement("span");
        var isCorrect = options.question.isAnswerCorrect();
        span.innerHTML = isCorrect ? "Correct" : "Incorrect";
        span.style.color = isCorrect ? "green": "red";
        var header = options
            .htmlElement
            .querySelector("h5");
        if(!isCorrect) {
            header.style.backgroundColor = "salmon";
            var radio = options.htmlElement.querySelector('input[value="' + options.question.correctAnswer + '"]');
            if(!!radio) {
                radio.parentElement.style.color = "green";
            }
        }
        header.appendChild(span);
    });
        
            $("#surveyElement").Survey({
            model: survey 
            });
        

                    
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Use customer render and display mode to review a quiz results, jQuery Survey Library Example</title>

<meta name="viewport" content="width=device-width" />
    <script src="https://unpkg.com/jquery"></script>
<script src="/DevBuilds/packages/survey-jquery/survey.jquery.js"></script>
<link href="/DevBuilds/packages/survey-knockout/modern.css" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" href="./index.css">

</head>
<body>
    
            <div id="surveyElement" style="display:inline-block;width:100%;">
            </div>
    <div id="surveyResult"></div>

<script type="text/javascript" src="./index.js"></script>

</body>
</html>