0

I want to send a parameter value over http using <a> tag but I do not want it to be set in the href attribute.

Is there a way to do just that so that I could receive that value on the server side?

Thanks.

Taz
  • 3,718
  • 2
  • 37
  • 59
skip
  • 12,193
  • 32
  • 113
  • 153
  • 1
    Not sure what you are trying to accomplish here. You could either use a hidden field (preferred) or a custom attribute although the html wouldn't technically be valid. – Keith Apr 10 '12 at 18:13
  • why not send it via a $_POST variable? – Zanrok Apr 10 '12 at 18:13
  • @Keith & @Zanrok: I just need to send an information to the server about the type of link clicked based on which I need a form to be displayed. Can't use the POST request there because I am using `href` to setting up a form and I would like to use the same URL for processing(POST) request as well. I would like to have a valid HTML for the same to be done. And I don't want that type-of-link-clicked information to be sent to the server in the `href` attribute. – skip Apr 10 '12 at 18:18
  • The POST approach should work fine for you if you give the type-of-link form a post variable that doesn't appear in the main form. Then the server can display the form if that variable is present, and otherwise process the form submission. – Russell Zahniser Apr 10 '12 at 19:02

1 Answers1

0

Either use JS to submit a (hidden) form.

<form id="foo" method="post" action="servletURL">
    <input type="hidden" name="yourParamName" value="yourParamValue" />
</form>
<a href="#" onclick="document.getElementById('foo').submit(); return false;">link</a>

Or use CSS to style the default submit button to look like a link.

<form id="foo" method="post" action="servletURL">
    <input type="hidden" name="yourParamName" value="yourParamValue" />
    <input type="submit" value="link" class="link" />
</form>

with

input[type=submit].link {
    margin: 0;
    border: 0;
    background: transparent;
    color: blue;
    text-decoration: underline;
    cursor: pointer;
    overflow: visible;
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555