FormValidation.js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Validation</title>
</head>
<body>
<form action="https://www.google.com" onsubmit="return func()">
<input id="ip1" type="text" name="userName" onkeyup="validate()">
<span id="sp"></span>
<input id="ip2" type="password" name="password" onkeyup="validate()">
<span id="sp2"></span>
<input type="submit" >
</form>
<script>
const func =()=>{
const val1 = document.getElementById('ip1').value;
const val2 = document.getElementById('ip2').value;
if(val1.length == 0 ){
return false;
} else if(val2.length==0){
return false;
}else{
return true;
}
}
const validate=()=>{
const val1 = document.getElementById('ip1').value;
const val2 = document.getElementById('ip2').value;
if(val1.length ==0 ){
document.getElementById("sp").innerHTML ="username required"
}else if(val2.length==0){
document.getElementById("sp2").innerHTML ="password required"
}else{
document.getElementById("sp").innerHTML =" "
document.getElementById("sp2").innerHTML =" "
}
}
</script>
</body>
</html>
Comments
Post a Comment