Validate Password in JavaScript

<!DOCTYPE html>
<html>
<head>
<script>
function matchpass()
{
var firstpassword=document.f1.password.value;
var secondpassword=document.f1.password2.value;

if(firstpassword==secondpassword){
return true;
}
else{
alert("password must be same!");
return false;
}
}
</script>
</head>
<body>

<form name="f1" action="post" onsubmit="return matchpass()">
Password:<br/> <input type="password" name="password" /> <br/><br/>
Re-enter Password:<br/> <input type="password" name="password2"/> <br/> <br/>
<input type="submit">
</form>
</body>
</html>