在另一个表格中提交表单 [英] Submitting form located within another form

查看:77
本文介绍了在另一个表格中提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看这个HTML:

 < head> 
< title>测试页面< /标题>
< script type =text / javascript>
函数submitForm(){
document.getElementById(form2)。submit();
}
< / script>
< / head>
< body>
< form id =form1name =form1>
< input type =hiddenname =test1value =test/>

< form id =form2name =form2action =http://google.com>
< input type =hiddenname =test2value =nothing/>
< / form>
< / form>
< a href =javascript:void(0)onclick =submitForm()>提交< / a>
< / body>

我想要做的是使用javascript提交位于form1中的form2。我希望通过submitForm()函数来完成。问题是它看起来不起作用。我正在使用FireFox进行测试,并且始终得到一个错误,表示它未定义。有人知道我能如何让它工作吗?提前致谢!

解决方案

你不能像这样嵌套HTML表单。在form2开始之前结束form1。根据需要复制隐藏的输入。


Take a look at this html:

<head>
<title>Test page</title>
<script type="text/javascript">
    function submitForm() {
        document.getElementById("form2").submit();
     }
</script>
</head>
<body>
<form id="form1" name="form1">
    <input type="hidden" name="test1" value="test" />

    <form id="form2" name="form2" action="http://google.com">
        <input type="hidden" name="test2" value="nothing" />
    </form>
</form>
<a href="javascript:void(0)" onclick="submitForm()">Submit</a>
</body>

Thing I want to do is submitting form2 located within form1 with a javascript. I want this to be done by submitForm() function. The problem is that it doesn't appear to work. I'm using FireFox for testing and always get an error which says that it's undefined. Does anybody know how I can get it working? Thanks in advance!

解决方案

You can't nest HTML forms like that. End form1 before starting form2. Duplicate the hidden input if necessary.

这篇关于在另一个表格中提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆