var password = document.getElementById("password") , confirm_password = document.getElementById("confirmPassword"); document.getElementById('signupLogo').src = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSJZhNXJlPcwySsmDH7SnjadPo9eN5gDnsG0tqeL4vvUw&s"; enableSubmitButton(); function validatePassword() { if(password.value != confirm_password.value) { confirm_password.setCustomValidity("Passwords Don't Match"); return false; } else { confirm_password.setCustomValidity(''); return true; } } password.onchange = validatePassword; confirm_password.onkeyup = validatePassword; function enableSubmitButton() { document.getElementById('submitButton').disabled = false; document.getElementById('loader').style.display = 'none'; } function disableSubmitButton() { document.getElementById('submitButton').disabled = true; document.getElementById('loader').style.display = 'unset'; } function validateSignupForm() { var form = document.getElementById('signupForm'); for(var i=0; i < form.elements.length; i++){ if(form.elements[i].value === '' && form.elements[i].hasAttribute('required')){ console.log('There are some required fields!'); return false; } } if (!validatePassword()) { return false; } onSignup(); } function onSignup() { var xhttp = new XMLHttpRequest(); xhttp. { disableSubmitButton(); if (this.readyState == 4 && this.status == 200) { enableSubmitButton(); } else { console.log('AJAX call failed!'); setTimeout(function(){ enableSubmitButton(); }, 1000); } }; xhttp.open("GET", "ajax_info.txt", true); xhttp.send(); }