How to submit a form with JavaScript by clicking a

2019-01-02 20:10发布

Instead of a submit button I have a link:

<form>

  <a href="#"> submit </a>

</form>

Can I make it submit the form when it is clicked?

8条回答
零度萤火
2楼-- · 2019-01-02 20:45
document.getElementById("theForm").submit();

It works perfect in my case.

you can use it in function also like,

function submitForm()
{
     document.getElementById("theForm").submit();
} 

Set "theForm" as your form ID. It's done.

查看更多
余生请多指教
3楼-- · 2019-01-02 20:46

this works well without any special function needed. Much easier to write with php as well. <input onclick="this.form.submit()"/>

查看更多
登录 后发表回答