最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Send a form using javascript without knowing the name - Stack Overflow

programmeradmin0浏览0评论

To use the form submit javascript function you need to know the name of the form.

document.forms["myform"].submit();

or

document.myform.submit();

to submit

<form name="myform">...</form>

In my case i have a pletely random name as form name. What I do know is that there is always only one form element present at the page. Any ideas to submit the form using javascript?

<form name="145f88f84584594">...</form>

To use the form submit javascript function you need to know the name of the form.

document.forms["myform"].submit();

or

document.myform.submit();

to submit

<form name="myform">...</form>

In my case i have a pletely random name as form name. What I do know is that there is always only one form element present at the page. Any ideas to submit the form using javascript?

<form name="145f88f84584594">...</form>
Share Improve this question asked Oct 22, 2011 at 18:04 Roel VeldhuizenRoel Veldhuizen 4,7339 gold badges45 silver badges79 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 6

document.forms holds all forms.

This should work: document.forms[0].submit();.

document.getElementsByTagName("form")[0].submit();

or if you're using jQuery:

$("form:first").submit();

Try: document.getElementsByTagName("form")[0].submit()

You can also just do: 'document.forms[0].submit();'

ps. learning jQuery will be worth the time if you are dealig with dom elements.

发布评论

评论列表(0)

  1. 暂无评论