I have been searching in documentation how to validate two passwords, but I don't understand much about how to do it, I am just getting into these languages and I would like if someone could explain or teach me how to do it please. this is my html code but i don't know if i need javascript too and how do i call the html file in java. I have also seen that they put the java code in the HTML document but I don't understand which is the html part and which is the java part.
Here my code adding what they provided me
<html>
<head>
<meta charset = "utf-8">
<title>Registro</title>
<link rel="stylesheet" href="../css/registro.css">
</head>
<body>
<div class="HS">
<img src="../img/House_Student.png" class="letter" alt"la">
</div>
<div class="titulo">
<h1>Registrate</h1>
</div>
<div class="caja_login">
</div>
<div class="formulario" align="left">
<form action="registro.php" name="formulario" id="formulario" method="post">
<label for="Introduce tu nombre">Nombre: </label>
<input type="text" name="nombre" placeholder="ej. Luis Ricardo"
required="" pattern="[a-z-A-Z-á-ú]+"
title="Unicamente escriba su nombre. No se aceptan numeros en este espacio. Si tiene mas de un nombre escriba unicamente uno.">
<p> </p>
<label for="Introduce tu apellido paterno">Apellido paterno: </label>
<input type="text" name="a_paterno" placeholder="ej. Hernández"
required="" pattern="[a-z-A-Z-á-ú]+"
title="Unicamente escriba su apellido paterno. No se aceptan numeros en este espacio">
<label for="Introduce tu apellido materno">Apellido materno: </label>
<input type="text" name="a_materno" placeholder="ej. Rodríguez"
required="" pattern="[a-z-A-Z-á-ú]+"
title="Unicamente escriba su apellido paterno. No se aceptan numeros en este espacio">
<p> </p>
<label for="Introduce tu edad">Edad: </label>
<input type="number" name="edad" placeholder="ej. 50"
required="" min="1" max="120"
title="Escriba su edad en este espacio. Minimo 1 y maximo 120">
<label for="Introduce tu Pais">pais: </label>
<input type="text" name="pais" placeholder="ej. México"
required="" pattern="[a-z-A-Z-á-ú]+"
title="Escriba el pais de su procedencia. No se aceptan numeros en este espacio">
<p> </p>
<label for="Introduce tu Correo">Correo(opcional): </label>
<input type="email" name="correo" placeholder="[email protected]"
title="Su correo no tiene '@' es necesario que escriba correctamente su correo.
ejemplo: [email protected]">
<p> </p>
<label for="Introduce una contraseña">Contraseña: </label>
<input type="password" requiered="" name="contr" id="contr1"><br>
<label for="Introduce una contraseña">Confirma tu contraseña: </label>
<input type="password" requiered="" name="contr2" id="contr2"><br>
<input type="submit" value="Registro"><br>
</div>
<script>
formMain.addEventListener("submit", (e) => { // Escuchar cuando se envíe el formulario
if (contr1.value !== contr2.value) { // Comprobar si los valores de los inputs son iguales, si no lo son continuar
e.preventDefault(); // Prevenir que la página se recargue
err.innerHTML = "Las contraseñas no coinciden"; // Notificar al usuario
setTimeout(() => {
err.innerHTML = " ";
}, 1200); // Esperar 1.2 segundos y quitar el mensaje
}
});
</script>
</body>
</html>
You can do this with a simple javascript script:
Edit
The first block of code you have (JS) has to go at the end of
<body>
your site tag and between tags<script>
, otherwise javascript won't be able to fully read the DOM causing errors.Also there is no way you can do this without JavaScript, from the description of your question I can tell you that Java is a totally different programming language than JavaScript.
Note that