Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function hdq_before_mubasher99($quizID)
- {
- ?>
- <script>
- function hdq_custom_submit(){
- let data = {};
- let no_answers = 0;
- // mark each question with string on whether answer was right, wrong, or unanswered
- jQuery("#hdq_<?php echo $quizID; ?> .hdq_question").each(function(){
- let data = "";
- if(!this.classList.contains("hdq_question_title") && !this.classList.contains("hdq_results_wrapper")){
- let sel = jQuery(this).find(".hdq_correct");
- if(sel.length > 0){
- data = "Correct answer";
- } else {
- sel = jQuery(this).find(".hdq_wrong");
- if(sel.length > 0){
- data = "Incorrect answer";
- } else {
- data = "No answer selected";
- no_answers ++;
- }
- }
- }
- jQuery("<h2>" + data +"</h2>").prependTo(this);
- });
- // hdq_score is array of score (score/total questions)
- let c = hdq_score[0];
- let t = hdq_score[1];
- let p = (parseFloat(c) / parseFloat(t)) * 100;
- p = p.toFixed(2);
- let d = `<p>Total correct answers: <strong>${c}</strong><br/>
- Total Wrong Answers: <strong>${t}</strong><br/>
- Total Skipped Questions: <strong>${no_answers}</strong><br/>
- Total percentage: <strong>${p}%</strong>
- </p>`;
- let results_section = document.querySelectorAll(".hdq_share")[0];
- results_section.insertAdjacentHTML("beforebegin", d);
- return JSON.stringify(data); // expects a json string to be returned
- }
- </script>
- <?php
- }
- add_action('hdq_before', 'hdq_before_mubasher99');
- function hdq_submit_mubasher99($quizOptions)
- {
- array_push($quizOptions->hdq_submit, "hdq_custom_submit");
- return $quizOptions;
- }
- add_action('hdq_submit', 'hdq_submit_mubasher99');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement