Web Technologies

Web Technologies 

Slip12

Q.1) 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 . [Marks 30] 

Solution

user.html
<html>
<head>
<title>Javascript Login Form Validation</title>
<script>
function validate()
{
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
varcpassword = document.getElementById("cpassword").value;
if (username=="" || password=="" || cpassword=="" )
{
alert ("Fields Should not b empty");
//window.location = "success.html"; // Redirecting to other page.
//return false;
}
else if(password==cpassword)
{
alert("You entered all the details ");
return false;
}
else
alert("Password Fields doesn't match");
}
</script>
<body>
<h2>Javascript Login Form Validation</h2>
<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><input type="button" value="Login" id="submit" onclick="validate()"/></td>
</tr>
</table>
</form>
</body>
</html>

BCA Pratical Solution

My name is Vivek And I from Mumbai and Complete my Graduation Bca.my Age is 23 Years.

Post a Comment

Previous Post Next Post