var message = document.getElementById("message"); //message.style.visibility = "hidden"; var loginSubmit = function() { message.style.visibility = "hidden"; var username = document.getElementById('username').value; var password = document.getElementById('password').value; var promise = ajaxPost("/api/login", {"username": username, "password": password }); promise.success = function(response) { if(response.error) { message.innerHTML = response.error; message.style.visibility = "visible"; } else { window.location = "/dashboard/"; } }; promise.failure = function(response) { console.warn("Communication failure", response); } }; var loginButton = document.getElementById("login"); loginButton.addEventListener('click', loginSubmit, false); window.addEventListener("keypress", function(event) { var keyCode = event.which; if (keyCode == 13) { loginSubmit(); } }, false);