Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

a tag as a submit button?

Tags:

html

button

tags

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?

like image 857
theepan Avatar asked Sep 07 '11 20:09

theepan


People also ask

Can I use a tag as submit button?

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.

Which tag is used to create a submit button?

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.

Is there a submit tag in HTML?

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.

How do you use a button as a tag?

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.


1 Answers

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(); } 
like image 62
James Allardice Avatar answered Sep 23 '22 18:09

James Allardice