Richard Rodriguez Richard Rodriguez - 4 months ago 9
HTML Question

Submit a html form without having a submit button?

Can I submit a html

<form>
with
<div>
instead of
<input type="submit">
?

Like this:

<form method="post" action="" id="myForm">
<textarea name="reply">text</textarea>
</form>

<div>Submit the form by clicking this</div>

Answer

Quite simple;

document.getElementById("myForm").submit();

And if you want to do it jQuery style (which I do not recommend for such a simple task);

$("#myForm").submit();