The javascript equivalent of @sibu's correct answer is:
function submitForm(button) { let form = button.closest("form"); if (form) form.submit(); }