Maybe a bit tricky for solve your problem but could work...or maybe gives you idea to solve it.
If you go to server after each step, it's not in javascript but in php you need to add validation.
As you like to go to server (php) between each step, you can have every form inputs at once and only display needed step.
You also needs a current-step input to know in php at witch step you are.
HTML
<form method="POST">
<input type="hidden" id="currentStep" value="">
<div class="container-step1">
<!-- Step 1 -->
<input type="hidden" id="B1Clicked" value="N">
Step 1
<button type="button" id="B1">Button 1</button>
<button type="submit" class="step-submit" current-step="1">Next</button>
</div>
<div class="container-step2">
<!-- Step 2 -->
<input type="hidden" id="B2Clicked" value="N">
Step 1
<button type="button" id="B2">Button 2</button>
<button type="submit" class="step-submit" current-step="2"id="Next">Next</button>
</div>
<div class="container-step3">
<!-- Step 3 -->
<input type="hidden" id="B3Clicked" value="N">
Step 1
<button type="button" id="B3">Button 3</button>
<button type="submit" class="step-submit" current-step="3"id="Next">Next</button>
</div>
</form>
JS
$( document ).ready(function() {
// Hide all steps
$("div[class^='container-step']").hide();
// Show only step container give by server
$('.container-step<?= $currentStep ?>').show();
$('#B1').onclick = function() {
$('#B1Clicked').value('Y');
};
$('#B2').onclick = function() {
$('#B2Clicked').value('Y');
};
$('#B3').onclick = function() {
$('#B2Clicked').value('Y');
};
// Set current step
$('.step-submit').on('click', function(e) {
var currentStepValue = $(e.target).attr('current-step');
$('#currentStep').value(currentStepValue);
return true;
});
});
PHP
// Read current step from interface
$currentStep = filter_input(INPUT_POST, 'currentStep');
// Test for first show
if (null == $currentStep) $currentStep = 1;
// Fetch all step data
$b1Clicked = filter_input(INPUT_POST, 'B1Clicked');
$b2Clicked = filter_input(INPUT_POST, 'B2Clicked');
$b3Clicked = filter_input(INPUT_POST, 'B3Clicked');
// If all step has been clicked -> do validation
if ($b1Clicked == 'Y' && $b2Clicked == 'Y' && $b3Clicked == 'Y') {
// Add your validation here
}