I am trying to call a JavaScript function when the submit button of a form is clicked.
For some reason, the function is not called when it is named \'submit\', but when
Because submit()
is the reserved function to submit a form in core JS.
For example, if your form had an id like myform
, you could do this to submit it via JS:
document.form['myform'].submit();
So calling that function you're actually submitting the form and not calling your custom function.
EDIT: I forgot to mention, it only works inside the form because it's calling the submit function of that form. Out of it it's not available anymore (since the body tag doesn't have a submit function).