javascript - And again: submit is not a function

I have the following code for my form:
<form name="myform" id='form' class="form" method='post' accept-charset='UTF-8' action="action.php">
<div>
<input type='submit' id="sendbtn" value='Hello' class="loginbutton">
</div>
</form>
In my Javascript I have a form checker that - if the check succeeds - should submit the form. However - that doesn't work.
The javascript is:
const sendit = document.getElementById("sendbtn");
function showSuccess(input){
const formControl = input.parentElement;
formControl.className = 'form-control success';
sendit.submit();
}
That code throws the error:
Uncaught TypeError: sendit.submit is not a function
Because I already learned that names or ids called "submit" override the submit-function, I checked my code for the usage of "submit". But there's simply no other usage in the php or the javascript except an addEventListener for the type "submit".
What could be the problem here?
Answer
Solution:
You are pointing theinput
, not theform
, which is the element who will submit the form.
const sendit = document.getElementById("form");
Your function that submits the form, has to point to the form idform
. You are pointing a button, which doesn't have the submit event.
Answer
Solution:
Thanks for the hints.
I now added another function:
function submitForm(form) {
sendit.submit();
}
And I call it by submitForm(); from within the function "showSuccess". But that throws the same error.
Uncaught TypeError: sendit.submit is not a function
I should clearify that I am just starting with javascript. My problem seems stupid to you, but is still complex for me.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: 403 this action is unauthorized.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.