function Check(field, err) {
var div = document.createElement('div')
div.innerHTML = err;
div.className = "error";
field.parentNode.appentChild(div);
}
Check(Fields.RegConfirmPassword, Error.RegConfirmPassword);
Check( document.getElementById('usernamesignup') , "Your login is incorrect!");
Uncaught TypeError: field.parentNode.appentChild is not a functionCheck @ CheckForm.js:11RegistrationCheck @ CheckForm.js:52onclick @ index.php:75
Вот полный файл:
// Check registration
function RegistrationCheck() {
function Check(field, err) {
var div = document.createElement('div')
div.innerHTML = err;
div.className = "error";
field.parentNode.appentChild(div);
}
var Fields = {
Submit: document.getElementsByClassName("signin button")[0].firstChild,
RegLogin: document.getElementById("usernamesignup"),
RegPassword: document.getElementById("passwordsignup"),
RegConfirmPassword: document.getElementById("passwordsignup_confirm"),
Email: document.getElementById("emailsignup")
}
var Error = {
Login: "Your login is incorrect!",
Password: "Your password is incorrect!",
Email: "Your Email is incorrect!",
RegConfirmPassword: "Check confirm of password!",
Sum: 0
}
var Data = {
Login: Fields.RegLogin.value,
Password: Fields.RegPassword.value,
Email: Fields.Email.value,
RegConfirmPassword: Fields.RegConfirmPassword.value,
}
var Regular = {
Login: /^[a-z0-9_-]{3,16}$/,
Email: /^[-\w.]+@([A-z0-9][-A-z0-9]+\.)+[A-z]{2,4}$/,
Password: /^[a-z0-9_-]{6,18}$/
}
if (!Regular.Login.test(Data.Login)) {
Error.Sum++;
alert("Your login is incorrect!");
Check( document.getElementById('usernamesignup') , "Your login is incorrect!");
}
if (!Regular.Email.test(Data.Email)) {
Error.Sum++;
alert("Your Email is incorrect!");
Check(Fields.Email, Error.Email);
}
if (!Regular.Password.test(Data.Password)) {
Error.Sum++;
alert("Your password is incorrect!");
Check(Fields.RegPassword, Error.Password);
}
if (Data.Password != Data.RegConfirmPassword) {
Error.Sum++;
alert("Check confirm of password!");
Check(Fields.RegConfirmPassword, Error.RegConfirmPassword);
}
if (Error.Sum == 0) {
Fields.Submit.onclick = function () { return true; };
Fields.Submit.click();
}
}