I am trying to make a login page for a web app. How do I only allow onclick="" of a button once the username and password have been validated?
Below is what I have:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Customer Login</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Language" content="ch-cn">
<script>
function validate() {
var uname = document.getElementById("uname");
var upass = document.getElementById("upass");
if(uname.value == ""){
alert("username can't be null");
return false;
}
else if(upass.value ==""){
alert("password can't be null");
return false;
}
else
return true;
}
</script>
</head>
<body>
This is the Customer login page.
<br>
<form method="post" action="custlogin">
user SSN:<input type="text" id="uname" name="userSSN"><br>
<br> password:<input type="password" id="upass" name="pwd"><br>
<br>
<button type="submit" value="submit" onclick="return validate();">submit</button>
<button type="reset" value="reset">reset</button>
</form>
</body>
</html>
Where are you storing the info for what valid usernames and passwords are? A database?
I am attempting to help, but I am no expert.
To my understanding would need to test the values of the inputs against the value of what is already saved in your Database.
something like
have the form fields with ids userName , passWord
if {
userName == howeverYouReferenceAusernameindb
&& passWord == @tablename.columnName
{
login code here
}
else { "please put valid creds"
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.