To submit form using an a tag with JavaScript, we can call the form’s submit
method.
For instance, we write
<form name="myForm" action="handle-data.php">
Search: <input type="text" name="query" />
<a href="javascript: submitform()">Search</a>
</form>
to add a form.
Then we write
function submitform() {
document.myForm.submit();
}
to define the submitForm
function which we set as the value of the href attribute of the a
element.
In it, we get the by its name with document.myForm
.
And then we call submit
to submit the form.
Conclusion
To submit form using an a tag with JavaScript, we can call the form’s submit
method.