donvitto donvitto - 1 month ago 15
HTML Question

submit form from a link

This is what I am trying to do without success :

<form name="something" action="ht.php" method="post">
<a href="#" onclick="document.url.submit('helloworld');">Submit</a>
</form>


When I click on the link I want to post the value
helloworld
to
ht.php
. How can I do this?

Answer

You can't just do document.url.submit(), it doesn't work like that.

Try this:

<form id="myForm" action="ht.php" method="post">
    <input type="hidden" name="someName" value="helloworld" />
    <a href="#" onclick="document.getElementById('myForm').submit();">Submit</a>
</form>

That should work!