How can I submit a POST form using the <a href="..."> tag?

hozaifa picture hozaifa · Nov 17, 2011 · Viewed 310.4k times · Source

How can I submit a POST form to showMessage.jsp using just the <a href="..."> tag?

<form action="showMessage.jsp" method="post">
    <a href="showMessage.jsp"><%=n%></a>
    <input type="hidden" name="mess" value=<%=n%>/>
</form>

Answer

rybo111 picture rybo111 · Feb 27, 2014

No JavaScript needed if you use a button instead:

<form action="your_url" method="post">
    <button type="submit" name="your_name" value="your_value" class="btn-link">Go</button>
</form>

You can style a button to look like a link, for example:

.btn-link {
    border: none;
    outline: none;
    background: none;
    cursor: pointer;
    color: #0000EE;
    padding: 0;
    text-decoration: underline;
    font-family: inherit;
    font-size: inherit;
}