Monday, 8 April 2019

Validation Using JavaScript

Valid.html
_______________________

<!DOCTYPE html>
<html>
<head>
<title>Form Validation</title>
<script type="text/javascript">

function validate() {
var username=document.getElementById('uname');
var password=document.getElementById('password');

if (username.value.trim()=="")
{

document.getElementById('lbuser').style.visibility="visible";
uname.style.border="solid 3px red";
return false;
}else if (password.value.trim()=="")
{
alert("please enter password");
return false;
     
}else if (password.value.trim().length<5)
{
alert("password lenght should be 5 ");
return false;
}else
{
return true;
}

}

</script>

</head>
<body>

<form onsubmit="return validate()" action="message.html">
<input type="text" id="uname" placeholder="username">
<label id="lbuser" style="color: red; visibility: hidden;">Please enter username</label>
</br></br>
<input type="password" id="password" placeholder="password"></br></br>
<button type="submit">submit</button>
</form>

</body>
</html>


No comments:

Post a Comment