Наконец-то я нашел свою ошибку. Значения, которые я ввел / нет, должны проверяться после нажатия кнопки (не раньше). Так что script
должно быть таким.
<script>
$("#validationAlert").hide();
$("#btn-sign-up").click(function showAlert() {
var firstName = document.getElementById('firstName').value;
var lastName = document.getElementById('lastName').value;
var email = document.getElementById('email').value;
var userName = document.getElementById('username').value;
var password = document.getElementById('password').value;
var repeatPassword = document.getElementById('repeatpassword').value;
var securityQuestion = document.getElementById('securityQuestion').value;
var answer = document.getElementById('answer').value;
if (firstName == "") {
// alert("URL is mandatory!");
$("#firstName").focus();
alert(firstName);
$("#validationAlert").fadeTo(2000, 500).slideUp(500, function () {
$("#validationAlert").slideUp(1500);
});
return false;
} else if (lastName == "") {
$("#lastName").focus();
alert("2");
$("#validationAlert").fadeTo(2000, 500).slideUp(500, function () {
$("#validationAlert").slideUp(1500);
});
return false;
} else if (email == "") {
document.getElementById('email').focus();
$("#validationAlert").fadeTo(2000, 500).slideUp(500, function () {
$("#validationAlert").slideUp(1500);
});
return false;
} else if (userName == "") {
document.getElementById('username').focus();
$("#validationAlert").fadeTo(2000, 500).slideUp(500, function () {
$("#validationAlert").slideUp(1500);
});
return false;
} else if (password == "") {
document.getElementById('password').focus();
$("#validationAlert").fadeTo(2000, 500).slideUp(500, function () {
$("#validationAlert").slideUp(1500);
});
return false;
} else if (repeatPassword == "") {
document.getElementById('repeatpassword').focus();
$("#validationAlert").fadeTo(2000, 500).slideUp(500, function () {
$("#validationAlert").slideUp(1500);
});
return false;
} else if (securityQuestion == "-1") {
document.getElementById('securityQuestion').focus();
$("#validationAlert").fadeTo(2000, 500).slideUp(500, function () {
$("#validationAlert").slideUp(1500);
});
return false;
} else if (answer == "") {
document.getElementById('answer').focus();
$("#validationAlert").fadeTo(2000, 500).slideUp(500, function () {
$("#validationAlert").slideUp(1500);
});
return false;
}
return true;
});
</script>