Submitting A HTML Form Using JavaScript

19th June 2008 - 1 minute read time

In order to submit a form using an event you need to run a click event on any submit button in the form. Take the following form.

  1. <form method="post" onsubmit="alert('Form submitted!'); return false;">
  2. <input type="text" name="testvalue" value="" />
  3. <input type="submit" name="submit" id="submit" value="Submit" />
  4. </form>

To run a submit event using JavaScript we just find the submit button via the id and run click() against it.

document.getElementById('submit').click();

That's it!

Add new comment

The content of this field is kept private and will not be shown publicly.