Instead of a submit button I have a link:
<form>
<a href="#"> submit </a>
</form>
Can I make it submit the form when it is clicked?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The best way
The best way is to insert an appropriate input tag:
The best JS way
Enclose the latter JavaScript code by an
DOMContentLoadedevent (choose onlyloadfor backward compatiblity) if you haven’t already done so:The easy, not recommandable way (the former answer)
Add an
onclickattribute to the link and anidto the form:All ways
Whatever way you choose, you have call
formObject.submit()eventually (whereformObjectis the DOM object of the<form>tag).You also have to bind such an event handler, which calls
formObject.submit(), so it gets called when the user clicked a specific link or button. There are two ways:Recommended: Bind an event listener to the DOM object.
Not recommended: Insert inline JavaScript. There are several reasons why this technique is not recommendable. One major argument is that you mix markup (HTML) with scripts (JS). The code becomes unorganized and rather unmaintainable.
Now, we come to the point at which you have to decide for the UI element which triggers the submit() call.
A button
A link
Apply the aforementioned techniques in order to add an event listener.