I am trying to join a username and a password into one field once I have encoded them into base64. My problem comes when creating a hidden type input, when I send the form, it only sends username and password (both encoded) but it does not join them. The following code is where I have the problem, I think the problem is in the script below the form.
//Jade file
extends ./layout.jade
block contenido
div(class="d-flex justify-content-center center-block big-top-space")
form(class="col-md-6" action="/user/login" method="POST" id="formData" name="myform")
div(class="form-group")
label(for="username") Usuario
input(type="text" name="username" placeholder="Usuario" id="username" class="form-control")
div(class="form-group")
label(for="password") Contraseña
input(type="password" name="password" placeholder="Contraseña" id="password" class="form-control")
div(class="row top-space")
div(class="col-xs-12 col-sm-6")
input(type="submit" value="Iniciar sesión" class="btn btn-info" onclick="toBase64()")
div
input(type="hidden" id="joint")
div(class="col-xs-12 col-sm-6 text-right")
a(href="/signup") No tengo cuenta
script.
function toBase64(){
var username = btoa(document.getElementById("username").value);
var password = btoa(document.getElementById("password").value);
document.getElementById("joint").value = username+":"+password;
}