JSP Form action and onsubmit : After I submit the form, the form will ignore the onsubmit whether the return is true or false, the form will directly go to form action. What I want is to validate the input, if it is null it will remain at the same page and pop up an alert.

This is my JSP javascript

    <script>
        function validLogin() {
            if (document.login.username.value == "") {
                alert("Please enter Login Name.");
                document.loginform.userName.focus();
                return false;
            }
            if (document.login.password.value == "") {
                alert("Please enter password.");
                document.userform.password.focus();
                return false;
            }
            alert("Welcome User");
            return false;
        }
    </script>


This is my JSP Form

    <form action="Login" method="post" name="login" onsubmit="return validLogin();">
