I have a textarea that submits when the input field is not empty. Assuming I want to prevent multiple submission on pressing the enter key simultanouesly with the following, it only submits each time I refresh the page. this is the code:
window.formWasSubmitted = false;
document.getElementById('new-input').addEventListener('keyup', function (e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 13 && $.trim($(this).val()) && !window.formWasSubmitted) { // enter key press && $(this).val().length > 0
e.preventDefault();
window.formWasSubmitted = true;
send();
}
//window.formWasSubmitted = false;
});
please how can I allow the textarea to submit without refreshing the page on entering data each time