So because I need to workaround some built-in form functionality in software that we use, I want to trigger a click on an element, by pressing enter.
This is my script:
let submitButton = document.querySelector('.test');
submitButton.addEventListener('click', submitForm, false);
submitButton.addEventListener('keydown', function(key) {
if (key.keyCode == '13') {
key.preventDefault();
submitButton.click();
}
});
function submitForm() {
// do something
}
Clicking on the div with class="test"
triggers an external script which only gets triggered on button click. Now for user experience I want to trigger this aswell on press of enter. According to documentation it should be like the above, but pressing enter doesn't trigger the script.
Does anybody know how to fix this?