Submitting A HTML Form Using JavaScript
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.
<form method="post" onsubmit="alert('Form submitted!'); return false;">
<input type="text" name="testvalue" value="" />
<input type="submit" name="submit" id="submit" value="Submit" />
</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!
Write a comment