Skip to content
doubtly

1 answer

Answer: Get the form element and call its submit() method (or requestSubmit()).

<form id="myForm" action="/save" method="post">
  <input type="text" name="username">
</form>
<button onclick="sendForm()">Send</button>

<script>
function sendForm() {
  document.getElementById("myForm").submit();
  // or: document.forms["myForm"].submit();
}
</script>

form.submit() sends the form directly to the URL in action. Note that it skips the form's onsubmit handler and HTML validation such as required.

If you want validation and the submit event to run, use form.requestSubmit(), which behaves like the user clicking a submit button.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.