Search code examples
htmlbuttontags

a tag as a submit button?


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?


Solution

  • 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();
    }