Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

forms

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

like image 706
Souad Avatar asked Jun 13 '13 02:06

Souad


People also ask

How can I submit a form without using JavaScript?

Use the <noscript></noscript> tags to define a "normal" submit-button when javascript is disabled. Show activity on this post. You could maybe use the <noscript> tag and encapsulate the above code with the button type as submit. If the client has js, the code inside the noscript will be ignored.

Can you submit a form with an anchor tag?

You can use href=”#top” or href=”#” to link to the top of the current page. To use the anchor tag as submit button, we need the help of JavaScript. To submit the form, we use JavaScript . submit() function.

How do I submit a form by link?

In the body tag, created an HTML form and specify the id, method, and action of the form. In the form, specify an anchor tag with an event onclick. Create a function for JavaScript that will get executed when the link is clicked. When we click on the link, the function submitForm() will get executed.

Is it possible to submit a form without a submit button?

The form can be submitted without using submit button by implementing a specific event attribute or by clicking the link. This task can be done by using the OnClick event attribute or by using the form. submit() method in Javascript. Approach: The form.


1 Answers

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

like image 190
d-_-b Avatar answered Oct 04 '22 20:10

d-_-b