Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Harmonic Design

    (@harmonic_design)

    Hi kennyalmendral,
    that code was given to that user for an older out of date version of HD Quiz. I’ll post an updated version on this thread tomorrow.

    Thread Starter kennyalmendral

    (@kennyalmendral)

    Thank you, I’ll wait for it then…

    Plugin Author Harmonic Design

    (@harmonic_design)

    Hi kennyalmendral,
    you can use this updated code that should work well for you.

    function hdq_kennyalmendral()
    { ?>
    
    <script>
    setTimeout(function(){
    	hdq_create_prev_buttons();
    	jQuery(".hdq_quiz").on("click", ".hdq_prev_button", function(){
    		hdq_prev_click(this)
    	})
    	
    	jQuery(".hdq_quiz").on("click", ".hdq_next_button", function(){
    		hdq_next_click(this)
    	})
    }, 2000);
    	
    	
    function hdq_create_prev_buttons(){
    	let data = '<div class="hdq_prev_button hdq_button" data-id = "'+HDQ.VARS.id+'" style = "margin-right: 1rem">BACK</div>';
    	let hdq_pagination_areas = document.getElementsByClassName("hdq_next_button");
    	for(let i = 1; i < hdq_pagination_areas.length; i++){
    		hdq_pagination_areas[i].insertAdjacentHTML("beforebegin", data);
    	}
    	
    	let q = document.getElementsByClassName("hdq_finsh_button")[0];
    	data = '<div class="hdq_prev_button hdq_button hdq_hidden" data-id = "'+HDQ.VARS.id+'" style = "margin-right: 1rem">BACK</div>';
    	q.insertAdjacentHTML("beforebegin", data);
    }
    
    function hdq_next_click(){
    	if (HDQ.VARS.jPage === HDQ.EL.jPaginate.length) {
    		jQuery(".hdq_prev_button").removeClass("hdq_hidden");
    	}
    }
    
    function hdq_prev_click(el){
    	if (HDQ.VARS.jPage === HDQ.EL.jPaginate.length) {
    		jQuery(".hdq_finish .hdq_prev_button").addClass("hdq_hidden");
    		jQuery(".hdq_finish .hdq_finsh_button").addClass("hdq_hidden");
    	}	
    	
    	
    	HDQ.VARS.jPage = parseInt(HDQ.VARS.jPage - 1);
    	jQuery(".hdq_question").hide();
    	jQuery(".hdq_jPaginate").hide();
    	
    	let page = jQuery(".hdq_jPaginate");
    	let start = HDQ.VARS.jPage - 1;
    	let hdq_form_id = jQuery(el).attr("data-id");
    	
    	if(start >= 0){	
    		jQuery("#hdq_" + hdq_form_id + " .hdq_jPaginate:eq(" + parseInt(start) + ")")
    			.nextUntil("#hdq_" + hdq_form_id + " .hdq_jPaginate")
    			.show();
    	} else {
    		let start = jQuery("#hdq_" + hdq_form_id + " .hdq_question:first");
    		jQuery(start).show();
    		jQuery(start).nextUntil(".hdq_jPaginate:first").show();
    		
    		console.log(jQuery("#hdq_" + hdq_form_id + " .hdq_jPaginate:first"))
    	}
    	jQuery(".hdq_results_wrapper").hide(); // in case the results are below the quiz
    	jQuery(".hdq_question:visible").next(".hdq_jPaginate").show();
    	
    }
    </script>
    
    <?php }
    add_action("hdq_after", "hdq_kennyalmendral");
    Thread Starter kennyalmendral

    (@kennyalmendral)

    Thank you man, it works!

    shwe

    (@shwedingar)

    Hi,

    Great quiz plugin. Thank you.

    I’m trying to add “back” button as well. I’ve used the code above which appears to work well, except that the “back” button appears on the results page as well. If you click the back button on the results page it goes back but the results are already given.

    How can I remove the back button on the results page?

    Thanks you!

    Plugin Author Harmonic Design

    (@harmonic_design)

    :s there shouldn’t be a button on the results page. Can you please send me a link?

    shwe

    (@shwedingar)

    Hi, is there a way to share a link privately?
    I tried deactivating all plugins (except HD Quiz and Code Snippets – also deactivated all snippets except the one for the “back button”). No luck – the back button still appears on the results page.
    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Existing Previous Button Code’ is closed to new replies.