I am trying to create a simple web application. On my login page, I have a form with a text box, password and submit button. Form submission is prevented if both fields are empty. This is the script I use:
function checkLoginCredentials() { var usernameFormValue = $("#usernameForm").val().trim(); var passwordFormValue = $("#passwordForm").val().trim(); var validated; $("#loginForm").submit(function(event){ if (usernameFormValue === "" || passwordFormValue === "") { $("span").html("Enter a username or password"); validated = false } else { validated = true; } return validated; }); }
However, I noticed that after running the script and submitting the form, the user will no longer be able to log in again. The only alternative I can think of is ALL checks performed by my servlets and utility classes. Is there a way around this or checking for invalid entries, such as empty strings, with my Java classes?
source share