JavaScript - submit form example

0 points
Created by:
Dirask Community

In this article, we would like to show you how to submit a form in JavaScript.

Quick solution:

// add onsubmit event to the form, specify submit handling function and form fields
<form id="my-form" onsubmit="submitHandlingFunction(event)">
    Form field: <input type="text">
    <input type="submit">


Practical example

In this example, we will submit my-form. To do so, we use onsubmit event and submitForm() event handling function.

// ONLINE-RUNNER:browser;

<!doctype html>
    <form id="my-form" onsubmit="submitForm(event)">
      Username: <input type="text"><br>
      Password: <input type="password"><br>
      <input type="submit" value="Submit">

      var myForm = document.querySelector('#my-form');

      function submitForm(event) {
        console.log('onsubmit event occurred...');


Related posts

Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé