Title: Existing Previous Button Code
Last modified: August 11, 2020

---

# Existing Previous Button Code

 *  Resolved [kennyalmendral](https://wordpress.org/support/users/kennyalmendral/)
 * (@kennyalmendral)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/existing-previous-button-code/)
 * Hello, I’ve used the previous button code you’ve provided in here: [https://wordpress.org/support/topic/how-to-add-bottom-previous-question-on-paginate-mode/](https://wordpress.org/support/topic/how-to-add-bottom-previous-question-on-paginate-mode/)
 * However, when I click the back button, an error is displayed in the console: `
   Uncaught ReferenceError: jPage is not defined`
 * Do I need to include another third party JS library or something? Thank you

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

 *  Plugin Author [Harmonic Design](https://wordpress.org/support/users/harmonic_design/)
 * (@harmonic_design)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/existing-previous-button-code/#post-13235073)
 * 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](https://wordpress.org/support/users/kennyalmendral/)
 * (@kennyalmendral)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/existing-previous-button-code/#post-13235127)
 * Thank you, I’ll wait for it then…
 *  Plugin Author [Harmonic Design](https://wordpress.org/support/users/harmonic_design/)
 * (@harmonic_design)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/existing-previous-button-code/#post-13239478)
 * 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](https://wordpress.org/support/users/kennyalmendral/)
 * (@kennyalmendral)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/existing-previous-button-code/#post-13239895)
 * Thank you man, it works!
 *  [shwe](https://wordpress.org/support/users/shwedingar/)
 * (@shwedingar)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/existing-previous-button-code/#post-13412299)
 * 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](https://wordpress.org/support/users/harmonic_design/)
 * (@harmonic_design)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/existing-previous-button-code/#post-13414258)
 * :s there shouldn’t be a button on the results page. Can you please send me a 
   link?
 *  [shwe](https://wordpress.org/support/users/shwedingar/)
 * (@shwedingar)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/existing-previous-button-code/#post-13415055)
 * 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.

 * ![](https://ps.w.org/hd-quiz/assets/icon-256X256.gif?rev=2936040)
 * [HD Quiz](https://wordpress.org/plugins/hd-quiz/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/hd-quiz/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/hd-quiz/)
 * [Active Topics](https://wordpress.org/support/plugin/hd-quiz/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/hd-quiz/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/hd-quiz/reviews/)

 * 7 replies
 * 3 participants
 * Last reply from: [shwe](https://wordpress.org/support/users/shwedingar/)
 * Last activity: [5 years, 8 months ago](https://wordpress.org/support/topic/existing-previous-button-code/#post-13415055)
 * Status: resolved