Guest User

Untitled

a guest
Jan 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. <script type="text/javascript">
  2. jQuery(function($) {
  3. $(document).ready(function() {
  4.  
  5. // prepend a 'previous' button to all form-rows except the first
  6. $('<button>').addClass('previous').appendTo($('.inner').not(':first'));
  7.  
  8. // hide all form-rows, but not the first one
  9. $('.form-row').not(':first').hide();
  10.  
  11. // hide on last step
  12. $('button.next').last().hide();
  13.  
  14. // add the submit button to the last form-row
  15. $('<input>').addClass('submit').prop('type', 'submit').val('Submit').appendTo($('.form-row:last'));
  16.  
  17. // handle the previous button, we need to use 'on' here as the
  18. // previous buttons don't exist in the dom at page load
  19. $('.form-row').on('click', 'button.previous', function(e) {
  20. e.preventDefault();
  21. $(this).parents('div.form-row').hide().prev('div.form-row').show();
  22. });
  23.  
  24. $('button.next').click(function(e) {
  25. // prevent the next buttons from submitting the form
  26. e.preventDefault();
  27. // hide this form-row, and show the next one
  28. $(this).parents('div.form-row').hide().next('div.form-row').show();
  29. });
  30.  
  31. });
  32. });
  33. </script>
  34.  
  35. <?php $counter = 1; if(get_field('step_by_step_test')): ?>
  36. <?php while(the_repeater_field('step_by_step_test')): ?>
  37. <div class="form-row">
  38. <h2 style="float:left;margin-left:7px;"><?php the_title(); ?></h2>
  39. <h2 style="float:right;"><?php echo $counter; ?> of <?php echo $total; ?></h2>
  40. <div class="clear"></div>
  41. <div id="module-area" style="margin-top:0px!IMPORTANT;">
  42. <div id="modules-top"></div>
  43. <div id="modules-repeat">
  44. <?php if(get_sub_field('test_image')): ?>
  45. <?php while(has_sub_field('test_image')): ?>
  46. <img class="training" src="<?php echo the_sub_field('image'); ?>" />
  47. <?php endwhile; ?>
  48. <?php endif; ?>
  49.  
  50. <br /><br />
  51. <p class="training"><b><?php echo the_sub_field('question'); ?></b></p>
  52.  
  53. <?php if(get_sub_field('answer_options')): ?>
  54. <?php while(has_sub_field('answer_options')): ?>
  55. <p class="contact-form">
  56. <input style="width: 20px;" type="checkbox" name="CheckboxGroup<?php echo $counter; ?>[]" value="<?php echo the_sub_field('answer'); ?>" />
  57. <?php echo the_sub_field('answer'); ?>
  58. </p>
  59. <?php endwhile; ?>
  60. <?php endif; ?>
  61. <div class="inner"></div>
  62. <button class="next"></button>
  63. <div class="clear"></div>
  64. </div>
  65. <div style="margin-bottom:5px;" id="modules-bottom"></div>
  66. </div>
  67. </div>
  68. <?php $counter++; endwhile; ?>
  69. <?php endif; ?>
  70.  
  71. $(document).ready(function() {
  72.  
  73. var EZcounter = $('.form-row').length - 1;
  74.  
  75. {...your code...}
  76.  
  77. $('.form-row:nth-child(' + EZcounter + 'n) .next').click(function() {
  78. $('.form-row').show();
  79. $('.previous, .next').hide();
  80. });
  81. });​
Add Comment
Please, Sign In to add comment