function checkAvailability(string, elmtID, dataCollection) { var field = document.getElementById(elmtID); if (string.length === 0) { field.classList.remove("available"); field.classList.remove("unavailable"); return; } else { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState === 4 && this.status === 200) { if (this.responseText === "available") { field.classList.remove("unavailable"); field.classList.add("available"); } else { field.classList.remove("available"); field.classList.add("unavailable"); } } }; xmlhttp.open("GET", dataCollection + "?q=" + string, true); xmlhttp.send(); } } function checkRequiredField(elmtID) { var field = document.getElementById(elmtID); if (field.value === "") { field.classList.add("empty-required"); } else { field.classList.remove("empty-required"); } } document.getElementById("confirm-password").onkeyup = function () { var confirmField = document.getElementById("confirm-password"); var passwordField = document.getElementById("password"); if (confirmField.value !== passwordField.value) { confirmField.classList.add("not-match"); passwordField.classList.add("not-match"); } else { confirmField.classList.remove("not-match"); passwordField.classList.remove("not-match"); } }; document.getElementById("name").onkeyup = function () { checkRequiredField("name"); }; document.getElementById("username").onkeyup = function () { checkRequiredField("username"); }; document.getElementById("password").onkeyup = function () { checkRequiredField("password"); }; document.getElementById("email").onkeyup = function () { checkRequiredField("email"); }; document.getElementById("phone").onkeyup = function () { checkRequiredField("phone"); }