If the user name and password do not match it displays an alert but if I click ok to the alert the form is logged in. Can anyone tell me how to avoid it? Thanks.
<html> <f:view> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <h:form id="loginForm"> <h1><center>Login page</center> </h1> <h:panelGrid columns="2"> <h:outputLabel value="UserName"></h:outputLabel> <h:inputText id="name" value="#{user.name}"> </h:inputText> <h:outputLabel value="Password"></h:outputLabel> <h:inputSecret id="password" value="#{user.password}"></h:inputSecret> </h:panelGrid> <h:commandButton type="button" value="Login" action="logged" onclick="checkPassword(this.form)"></h:commandButton> </h:form> </body> <script type="text/javascript"> <!-- function checkPassword(form) { var passsword = form["loginForm:password"].value; var username=form["loginForm:name"].value; var confirmpassword ="welcome"; var confirmusername="admin"; if((passsword == confirmpassword)&&(username==confirmusername)) form.submit(); else alert("Username and Password does not match"); } --> </script> </f:view> </html>
1 Answer