To fix "Submit is not a function" error in JavaScript, we should make sure we call submit
on a form element.
For instance, we write
<form
action="product.php"
method="post"
name="frmProduct"
id="frmProduct"
enctype="multipart/form-data"
>
<input id="submitValue" type="button" name="submitValue" value="" />
</form>
to add a form with a submit button inside.
Then we write
const submitAction = () => {
document.getElementById("frmProduct").submit();
return false;
};
document.getElementById("submitValue").onclick = submitAction;
to select the button with getElementById
.
We set its onclick
property to the submitAction
function.
In submitAction
, we select the form with getElementById
and call submit
on the form.
Then we return false
to stop the default submit behavior.
onclick
only runs when we click on the button.