Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

forms

jsp

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> 
like image 391
hozaifa Avatar asked Nov 17 '11 14:11

hozaifa


People also ask

How do I send a POST request with a tag?

There is no way to POST an a element using only HTML. There is no attribute that controls whether to use POST or GET with an a element. You have to script it, if you want to abuse the semantics.

How do you POST a form in HTML?

The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute). The form-data can be sent as URL variables (with method="get" ) or as HTTP post transaction (with method="post" ). Notes on GET: Appends form-data into the URL in name/value pairs.

Can we use POST method in anchor tag?

This behaviour is specific to display tag library. It allows for easily bookmarkable search results. If you really intend to change this to make use of POST, then you'd need to rewrite the display tag library or bring in some jQuery to manipulate the links. The remnant of your questions boils nowhere.

What is the use of POST tag in HTML?

POST is used to send data to a server to create/update a resource. Some notes on POST requests: POST requests are never cached.


2 Answers

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; } 
like image 96
rybo111 Avatar answered Oct 30 '22 00:10

rybo111


You need to use javascript for this.

<form id="form1" action="showMessage.jsp" method="post">     <a href="javascript:;" onclick="document.getElementById('form1').submit();"><%=n%></a>     <input type="hidden" name="mess" value=<%=n%>/> </form> 
like image 30
naveed Avatar answered Oct 30 '22 01:10

naveed