Here is the code I’ve attempted to use.
//store score after the user submits
$quizID = ”;
$(‘.quiz’).on(‘click’, ‘.qsm-submit-btn’, function(){
$quizID = $(this).parents(‘form’).attr(‘id’);
console.log($quizID);
});
document.addEventListener( ‘qmnFormSubmit’, $(‘#’+$quizID), function( event ) {
console.log(‘hello2’);
moduleName = $(this).parents(‘.quiz’).attr(‘id’).toString();
score = $(‘.score’).text().toString();
}, false);
Hi @daemonhanky
I need to discuss this with my development team. Hopefully, I will get back to you with the solution.
Regards,
Sumit
I’ve come up with an interim solution if anyone is interested.
The loading animation starts when the quiz is busy processing results, so I am checking for if that exists when submit is clicked, then after a time I do what I want
(in this case creating a cookie with the score).
jQuery code is below:
//store score after the user submits
$('.quiz').on('click', '.qsm-submit-btn', function(){
quizID = $(this).parents('.quiz').attr('id').toString();
if($('.qsm_quiz_processing_box').length > -1){
setTimeout(function(){
moduleName = quizID;
score = $('.score').text().toString();
if(localStorage.getItem(moduleName) === null){
localStorage.setItem(moduleName, score);
}
},3000);
}
});
Thanks.
-
This reply was modified 4 years, 1 month ago by
daemonhanky. Reason: fixed typo
Hi @daemonhanky ,
There is a hook qsm_after_quiz_submit which you can use for calling custom js functions after submitting any quiz. Please check the below-given example. Let me know if you need more help.
jQuery(document).on(‘qsm_after_quiz_submit’,function(event,quiz_form_id){
event.preventDefault();
let polarQuestions = jQuery(‘.question-type-polar-s’);
if(polarQuestions.length >0){
qsmPolarSlider(‘answer’, polarQuestions);
}
});
Regards,
Sumit