Submit a form using <a> anchor element, without javascript

javascript submit form
javascript submit form onclick
html form
javascript form submit not working
button onclick submit form
html submit button action
form action
javascript form action submit

How to replace the submit button with a link without using javascript ? is there any way to add the submit attribute to a link ? because the form will not be sent by a simple link without "submit".

<form:form action="/getPage" >
     <div class="buttons">

         <a class="link" href=""> 
           <img src="icon.png" />
         </a>

     </div>         
</form:form>

I work in an application web so if i use javascript the link will not be mapped by the server ..

Try this:

CSS

button {
    background:none!important;
    border:none; 
    padding:0!important;
    /*border is optional*/
    border-bottom:1px solid #444; 
}

HTML

<button>your button that looks like a link</button>

Onclick JavaScript Form Submit, attributes like id, name, class, tag name as well. Generally, a form is submitted when the user presses a submit button. However, sometimes, you may need to submit the form programmatically using JavaScript. JavaScript provides the form object that contains the submit() method. Use the ‘id’ of the form to get the form object.

You can not submit a form using an <a> tag alone. You will need some type of javascript to assist, if you insist on using the <a> tag:

<a href="#" onclick="$(this).closest('form').submit()">Submit the Form</a>

or

<a href="#" onclick="document.getElementById('form-id').submit()">Submit the Form</a>

or super hack:

<a href="backendPage.php?param1=yes&param2=no">Submit the Form</a>, then on backendPage.php you can use $_GET requests to process information, and redirect the visitor to the intended page. But that's a horrible idea haha

Forms: event and method submit, How do I submit a form to the enter press? <input type="submit"> defines a button for submitting the form data to a form-handler. The form-handler is typically a page on the server with a script for processing input data. The form-handler is specified in the form's action attribute.

This can achieve the same effort and it looks like <a>

Note: btn btn-link comes from bootstrap

<button class="btn btn-link" type="submit"><img src="icon.png" /></button>

HTML Forms, -handler is typically a page on the server with a script for processing input data. It is an old post but I will leave the way I do to submit the form without using name tag inside the form: HTML <button type="submit" onClick="placeOrder(this.form)">Place Order</button> JS. function placeOrder(form){ form.submit(); } Hope this solution can help somebody else. TQ

There is an another way out. Using this method you can use any element to submit a form. Following is an example:

<span onclick="$('#submit').trigger('click')" style="cursor:pointer;">
     anything
</span>

Add a hidden submit button:

 <input style="display:none;" type="submit" id="submit"/>

This will behave exactly as actual submit button.

What happens when submit button is clicked, to the server and the browser will redirect away to the current address of the browser and append as query string parameters the values of the input fields. You can use the submit() method to submit an HTML form (i.e. <form>) using jQuery. The jQuery code in the following example will submit the form on click of the button (i.e. the <button> element) which has the type attribute set to button (i.e. type="button").

HTML DOM Form submit() Method, Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java  A new connection is created using curl_init() function, which takes the target URL as parameter (The URL where we want to post our data). The target URL is same as the "action" parameters of a normal form, which would look like this: <

HTML button form Attribute, <button type="submit" form="form1" value="Submit">Submit</button> this attribute must be equal to the id attribute of a <form> element in the same document. by Neeraj Agarwal In javascript onclick event, you can use form.submit() method to submit form. You can perform submit action by, submit button, by clicking on hyperlink, button and image tag etc.  You can also perform javascript form submission by form attributes like id, name, class, tag name as well.

Sending form data, Generally, a form is submitted when the user presses a submit button. However, sometimes, you may need to submit the form programmatically using JavaScript. JavaScript provides the form object that contains the submit() method. Use the 'id' of the form to get the form object. There are two main ways to submit a form: The first – to click <input type="submit"> or <input type="image">. The second – press Enter on an input field.

Comments
  • stackoverflow.com/questions/1367409/…
  • If you make your button a link, make sure Google and other search engines don't go through your page. You don't want a delete link triggered by the search engines.
  • The real question is: why must you use <a> to submit the form? What's wrong with <input> or <button>??
  • Hay hello man, I used this method and it worked fine, but didnt work when I changed href value to empty string (href=" ") can you tell me what is the significance of the #....
  • Hi @fazkan, thehref="#whatever" tells the browser to change the hash in the URL, which usually means no page reload (excluding angular, etc.). An empty href attribute will be the same as pointing to the current page which will reload the page. Alternatively, you could remove the href attribute completely and use CSS cursor:pointer to make the mouse hover look like a link.