function getToken(event) { event.preventDefault(); grecaptcha.ready(function() { grecaptcha.execute('6LexXqYiAAAAACwDpMGIg1OMnAXVJU0VmbEMQUD8', { action: 'submit' }).then(function(token) { var form = document.getElementById("inicio-sesion"); var boton_token = document.createElement('input'); boton_token.type = 'hidden'; boton_token.name = 'token'; boton_token.id = 'token'; boton_token.value = token; var boton_action = document.createElement('input'); boton_action.type = 'hidden'; boton_action.name = 'action'; boton_action.id = 'action'; boton_action.value = 'submit'; form.appendChild(boton_token); form.appendChild(boton_action); form.submit(); });; }); }