Hi I am trying to get "a" tag as a submit button. I found a code somewhere in the web. But it didn't work.
<a href="#" onclick="this.form.submit()">Submit</a>
Is there any code for to achieve my need?
You can use href=”#top” or href=”#” to link to the top of the current page. To use the anchor tag as submit button, we need the help of JavaScript. To submit the form, we use JavaScript . submit() function.
HTML Button tag can be used inside and outside the form. If you use it inside the form, it works as the submit button. You can also use it as reset button.
The Submit ButtonThe <input type="submit"> defines a button for submitting the form data to a form-handler. The form-handler is typically a file on the server with a script for processing input data. The form-handler is specified in the form's action attribute.
Using button tag inside <a> tag: This method create a button inside anchor tag. The anchor tag redirect the web page into the given location. Adding styles as button to a link: This method create a simple anchor tag link and then apply some CSS property to makes it like a button.
Give the form
an id
, and then:
document.getElementById("yourFormId").submit();
Best practice would probably be to give your link an id
too, and get rid of the event handler:
document.getElementById("yourLinkId").onclick = function() { document.getElementById("yourFormId").submit(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With