У вас несколько проблем с вашим кодом, в моем Chrome на MacOS он не переполняет стек, но показывает другие проблемы. Вместо того, чтобы указывать один, я просто работал над вашим JS. Поскольку вы используете jQuery, вы можете использовать его методы. Смотрите фрагмент для более.
$(function(){
$('.tab input').on('input', function(){
this.className = '';
})
$('#prevBtn').on('click', function(){
nextPrev(-1);
});
$('#nextBtn').on('click', function(){
nextPrev(1);
});
showTab(0);
});
function lastTabShown(index) {
return index >= $('.tab').length - 1
}
function showTab(index) {
$('#prevBtn').prop('disabled', index == 0);
var $tabs = $('.tab');
var $current = $tabs.filter(':visible');
var $next = $tabs.eq(index);
if ($current[0] && $current[0] != $next[0]) {
$current.hide();
}
$next.show();
updateStepIndicator(index);
if (lastTabShown(index)) {
$('#nextBtn').hide();
$('#submit').show();
} else {
$('#nextBtn').show();
$('#submit').hide();
}
}
function nextPrev(offset) {
if (!document.getElementById('regForm').checkValidity()) {
$('#submit').click();
return false;
}
var index = $('.tab:visible').index() + offset;
showTab(index);
}
function updateStepIndicator(index) {
var steps = $('.step');
steps.slice(0, index).addClass('finish');
steps.eq(index).addClass('active');
steps.slice(index + 1).removeClass('finish active');
}
* {
box-sizing: border-box;
}
body {
background-color: #f1f1f1;
}
#regForm {
background-color: #ffffff;
margin: 100px auto;
font-family: Raleway;
padding: 40px;
width: 70%;
min-width: 300px;
}
h1 {
text-align: center;
}
input {
padding: 10px;
width: 100%;
font-size: 17px;
font-family: Raleway;
border: 1px solid #aaaaaa;
}
/* Mark input boxes that gets an error on validation: */
input.invalid {
background-color: #ffdddd;
}
/* Hide all steps by default: */
.tab {
display: none;
}
.form-actions {
text-align: right;
}
.form-actions input[type=submit] {
display: none
}
button {
background-color: #4CAF50;
color: #ffffff;
border: none;
padding: 10px 20px;
font-size: 17px;
font-family: Raleway;
cursor: pointer;
}
button:hover {
opacity: 0.8;
}
#prevBtn {
background-color: #bbbbbb;
}
/* Make circles that indicate the steps of the form: */
.steps-container {
margin-top: 40px;
text-align: center;
}
.step {
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbbbbb;
border: none;
border-radius: 50%;
display: inline-block;
opacity: 0.5;
}
.step.active {
opacity: 1;
}
/* Mark the steps that are finished and valid: */
.step.finish {
background-color: #4CAF50;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="regForm" action="/action_page.php">
<h1>Register:</h1>
<div id="tabs">
<div class="tab">Name:
<p><input placeholder="First name..." name="fname" required></p>
<p><input placeholder="Phone..." title="Numbers only allowed" name="phone" pattern="^[0-9]*$"></p>
</div>
<div class="tab">Contact Info:
<p><input placeholder="E-mail..." name="email"></p>
<p><input placeholder="Phone..." name="phone"></p>
</div>
<div class="tab">Birthday:
<p><input placeholder="dd" name="dd"></p>
<p><input placeholder="mm" name="nn"></p>
<p><input placeholder="yyyy" name="yyyy"></p>
</div>
<div class="tab">Login Info:
<p><input placeholder="Username..." name="uname"></p>
<p><input placeholder="Password..." name="pword" type="password"></p>
</div>
</div>
<div class="form-actions">
<button type="button" class="button prev_btn" id="prevBtn">Previous</button>
<button type="button" class="button next_button" id="nextBtn">Next</button>
<button type="submit" class="button submit-button" id="submit" name="commit">Register</button>
</div>
<div id="step-circles" class="steps-container">
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
</div>
</form>