password - check confirm
by kursolle
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.4.1/milligram.css">
</head>
<body>
<main>
<h1>Meddelande i inputbox</h1>
<article>
<section>
<h2>Formuläret</h2>
<p>Ange två identiska lösenord för att komma vidare.</p>
<form action="?action=select" method="POST">
<input type="password" name="password" id="password" placeholder="Password" required />
<input type="password" name="confirm_password" id="confirm_password" placeholder="Confirm password" required />
<button type="submit" name="button" value="skicka">skicka</button>
</form>
</section>
<section>
<h2>Info</h2>
<p>För att kunna klicka på knappen och gå vidare till nästa sida så måste lösenorden vara identiska.</p>
</section>
</article>
</main>
</body>
</html>
CSS
main {
margin: 20px;
}
section {
flex: 0 0 auto;
margin: 10px;
width: 40vw;
}
article {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: space-between;
align-items: auto;
align-content: start
}
JavaScript
var password = document.getElementById("password")
var confirm_password = document.getElementById("confirm_password");
function validatePassword(){
if(password.value != confirm_password.value) {
confirm_password.setCustomValidity("Lösenorden är inte identiska");
} else {
confirm_password.setCustomValidity('');
}
}
password.onchange = validatePassword;
confirm_password.onkeyup = validatePassword;