Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit form using a link on JSP

Tags:

html

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?

like image 369
Onizudo Avatar asked Oct 19 '25 16:10

Onizudo


1 Answers

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).

like image 117
BalusC Avatar answered Oct 21 '25 04:10

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!