jQuery(function($) {
$(document).ready(function() {
// prepend a 'previous' button to all form-rows except the first
//$('<button>').text("<< Back").addClass('previous').appendTo($('.inner').not(':first'));
//$('<button>').text("<< Back").addClass('back-training').appendTo($('.inner').first());
// hide all form-rows, but not the first one
$('.form-row').not(':first').hide();
// hide on last step
$('button.next').last().hide();
// handle the previous button, we need to use 'on' here as the
// previous buttons don't exist in the dom at page load
/*$('.form-row').on('click', 'button.previous', function(e) {
e.preventDefault();
$(this).parents('div.form-row').hide().prev('div.form-row').show();
});*/
var score = 0;
$('button.next, input.check').click(function (e) {
// prevent the next buttons from submitting the form
e.preventDefault();
var correctAnswers = $(this).siblings().find('.correct-answer').length;
var totalUserCorrectAnswers = $(this).siblings().find('.correct-answer:checked').length;
var totalCheckedAnswers = $(this).siblings().find('input:checked').length;
var item = $(this).parents('div.form-row').find('.correct:first').data('progress');
var resultBubble = $('.quiz-progress-circle[data-progress="' + item + '"]');
if(correctAnswers === totalUserCorrectAnswers && totalUserCorrectAnswers === totalCheckedAnswers) {
resultBubble.removeClass("progress-incorrect");
resultBubble.addClass("progress-correct");
score += 1;
} else {
resultBubble.removeClass("progress-correct");
resultBubble.addClass("progress-incorrect");
}
// hide this form-row, and show the next one
$(this).parents('div.form-row').hide().next('div.form-row').show();
$('.finalscore').val(score);
if($(this).hasClass('do-submit-after-check')) {
$('form').trigger('submit');
}
});
// add the submit button to the last form-row
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.