D-Inventor
D-Inventor

Reputation: 480

use a tag to submit form to other page

I wanted to use an a tag to submit a form to another page. However, when I do this, and use href="" to go to this page, the form seems not to be submitted. It looks like this:

<form id="SomeForm" action="SomePage.php" method="GET">
    <!--Here are some inputs-->
</form>

<a href="SomePage.php" onclick="javascript:document.getElementById('SomeForm').submit();">
    The link to click on
</a>

When clicking on this link, The browser goes to the right page, but the submitted form is gone. I used a javascript code line to make one big URL for the page so it looked like it was submitted, but I would also like to be able to submit forms with method="POST". It workes if it is on the same page and href="#", but otherwise it doesn't. Is there a way to do this?

Upvotes: 0

Views: 78

Answers (1)

Accelerator
Accelerator

Reputation: 338

<a href="#" onclick="javascript:document.getElementById('SomeForm').submit();">
    The link to click on
</a>

alternative:

<div id="someID" onclick="javascript:document.getElementById('SomeForm').submit();">
    <!-- Click anywhere in this div to submit the form -->
</div>

Upvotes: 1

Related Questions