Skip to content

Instantly share code, notes, and snippets.

@DonerKebab
Created November 22, 2019 01:58
Show Gist options
  • Save DonerKebab/3df4087ec1321f1a647960f63000e7cf to your computer and use it in GitHub Desktop.
Save DonerKebab/3df4087ec1321f1a647960f63000e7cf to your computer and use it in GitHub Desktop.
hien thi error message su dung visibility
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Page Title</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
</head>
<body>
<div>
User name <input type="text" id="name"> <span id="invalidName" style="color: red; visibility: hidden;">Username is required.</span>
</div>
<div>
Password <input type="password" id="password"> <span id="invalidPw" style="color: red; visibility: hidden;">Password is required.</span>
</div>
<button onclick="login()">Login</button>
<script>
function login() {
var flag = true;
var name = document.getElementById("name").value;
var password = document.getElementById("password").value;
document.getElementById("invalidName").style.visibility = "hidden";
document.getElementById("invalidPw").style.visibility = "hidden";
if (name == '') {
document.getElementById("invalidName").style.visibility = "visible";
flag = false;
}
if (password == '') {
document.getElementById("invalidPw").style.visibility = "visible";
flag = false;
}
if(flag != false)
{
if (name == 'admin' && password == 'admin') {
alert("Dang nhap thanh cong");
} else {
alert("Dang nhap that bai");
}
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment