Onizudo
Onizudo

Reputation: 333

Submit form using a link on JSP

I want to submit a simple form, but instead of using a button, I want to do it through a link. Since I'm not using JSF, I cannot use the h:commandLink component. I do not know how to do it in plain JSP/HTML. Any ideas?

Upvotes: 4

Views: 13816

Answers (1)

BalusC
BalusC

Reputation: 1108652

There are two ways.

  1. Use CSS to style the button to look like a link.

    <input type="submit" value="link" class="link">
    

    with for example

    .link {
        margin: 0;
        border: 0;
        background: none;
        overflow: visible;
        color: blue;
        cursor: pointer;
    }
    
  2. Or, use JavaScript to grab the form and submit it.

    <form id="formid">
         <a href="#" onclick="document.getElementById('formid').submit()">link</a>
    </form>
    

    It only won't work in browsers with JS disabled. It's however what JSF h:commandLink is doing under the covers (JSF components just generates plain HTML/CSS/JS after all, the webbrowser doesn't understand anything else).

Upvotes: 14

Related Questions