I'm working on a change password page. In this page the user enters the new password and confirms the new password. If both the passwords are not matching it should be in the same page. If the passwords match, then the user gets directed to another page. I have tried all methods to redirect the page , but it is not happening. Please help !
function f1()
{
var newpass = document.getElementById('npass').value;
var confirmpass = document.getElementById('cpass').value;
if(newpass!=confirmpass)
{
document.getElementById('npass').value = "";
document.getElementById('cpass').value = "";
alert("Password Mismatch. Please enter again!");
//window.location.href = "/file.html";
// window.location = 'file.html';
// window.location.replace('file.html');
//window.location.assign("file.html");
//window.location.href = "file.html";
}
else
{
alert("Password Match");
// window.location.href= "/file.html";
// document.write("check");
}
}
</script>
<form method="POST" onsubmit="f1()">
<label for="npass">New Password:</label>
<input type="password" id="npass" placeholder="Enter New Password"
name="newpassword" required="required" size="8">
<label for="cpass">Confirm Password:</label>
<input type="password" id="cpass" placeholder="Confirm New Password"
name="cpass" required="required" size="8"><br><br>
<input type="submit" class="btn btn-info" name="submit" value="Submit">
</form>
The alert boxes are working but the page redirect is not happening. I have tried all the redirect methods as shown in the code. But still not working. New to javascript. Please help
placeholderattributes are redundant. They don't hold any information that is not already in the<label>elements. Nobody benefits from them, and you'll probably find that some screen reader users have to listen to both (which is a waste of their time). You should get rid of them.<br><br>— Since 1996, we have had CSS margins for this sort of thing.