There are four scenarios in password validation.
1) If pass1 is empty alert should popup
2) If pass2 is empty alert should popup
3) If pass1 is not equal to pass2 or vice versa alert should popup or if any of field left empty.
4) And last is of submitssion of form.
I have stuck in point 3 where if by mistake user forget to enter confirm password.
Here is my code i am having issue with this. I need help
<html>
<head>
<title>my validation form</title>
<style type="text/css">
</style>
<script type="text/javascript" src="myfile.js">
</script>
</head>
<body>
<form name="form1" method="GET" action="#" onsubmit="password()">
<label>enter name:</label><input type="text" name="txtname"><br>
<label>enter password:</label><input type="password" name="txtpass1" ><br>
<label>enter retype password:</label><input type="password" name="txtpass2" ><br>
<input type="submit" value="click me">
</form>
</body>
</html>
.js
function textbox()
{
var txt = document.form1.txtname;
if(txt.value == "" )
{
alert("please type somthing ");
txt.focus();
return false;
}
else
{
alert(" you type: " + txt.value + " value approved ");
}
return true;
}
function password()
{
var pass1=document.form1.txtpass1.value;
var pass2=document.form1.txtpass2.value;
if(pass1 == "")
{
if (pass2 == "")
{
alert("please type password");
}
return false;
}
if(pass1 != pass2)
{
alert("password does not match");
return false;
}
else if(pass2 == "")
{
alert("confirm password is required");
return false;
}
return true;
}