• Resolved daemonhanky

    (@daemonhanky)


    I’m looking to run a javascript function when the submit is successful for any quiz.

    Is there a javascript event/function that I can listen for in order to do this?

    Something like on(‘qsm_submit_success’, function(){ do_something });

    Thank you for an amazing plugin!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter daemonhanky

    (@daemonhanky)

    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

    Thread Starter daemonhanky

    (@daemonhanky)

    I appreciate the help.

    Thanks Sumit.

    Thread Starter daemonhanky

    (@daemonhanky)

    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
    sumitsanadhya

    (@sumitsanadhya)

    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

    Thread Starter daemonhanky

    (@daemonhanky)

    Exactly what I needed.

    Thank you so much!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Is there a Javascript on QSM submit function?’ is closed to new replies.