Sunday, 19 November 2017

WT-Slip12

12. Write a JavaScript program to compare the values of password and confirmed password field and display message accordingly. Also perform the validation to check any of the field should not be empty


<html>
<head>
<script>
function validate()
{
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var cpassword = document.getElementById("cpassword").value;
if (username=="" ||  password=="" || cpassword=="" )
{
alert ("Fields Should not b empty");
}
else if(password==cpassword)
{
alert("You entered all the details ");
return false;
}
else
alert("Password Fields doesn't match");
}
</script>
<body>
<div class="container">
<div class="main">
<caption>Javascript Login Form Validation</caption>
<form id="form_id" method="post" name="myform">
<table>
<tr>
<td>User Name :</td>
<td><input type="text" name="username" id="username"/></td>
</tr>

<tr>
<td>Password :</td>
<td><input type="password" name="password" id="password"/></td>
</tr


<tr>
<td>Confirm Password :</td>
<td><input type="password" name="cpassword" id="cpassword"/></td>
</tr>



<tr><td></td>
<td><input type="button" value="Login" id="submit" onclick="validate()"/></td>
</tr>


</table>
</form>
</div>
</body>
</html>