I can not see the results that I write in the fields of the form, I'm doing it in the following way but I do not get so much what I entered in the user field or in the password field.
function contrasena() {
//HTML
document.getElementById("cuerpoCentral").innerHTML =
'<form id="formLogin">' +
"Usuario:" + '<br>' +
'<input id="user" type="text" name="username">' + '<br>' + '<br>' + 'Contraseña:' + '<br>' +
'<input id="pass" type="password" name="pass">' + '<br>' +
'</form>' + '<br>' +
'<button onclick="contrasena()">' + 'Comprobar' + '</button>';
//JS
var myInput = document.getElementById("user");
var myInput2 = document.getElementById("pass");
alert(myInput.value);
alert(myInput2.value);
alert(myInput.value.length);
alert(myInput2.value.length);
}
<html>
<head>
<script src="contrasena.js"></script>
</head>
<body>
<div id="cuerpoCentral">
</div>
</body>
</html>