javascript 页面加载时自动提交表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16592312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Auto submit form on page load
提问by MDez
I'm having a bit of trouble with my current issue. Any help would be greatly appreciated.
我目前的问题有点麻烦。任何帮助将不胜感激。
I have a step in a 'signup process' which I don't need anymore, but I don't have time to reconfigure the entire process so I'm trying to auto submit the form on page load so it will basically skip over this step. Any thoughts?
我在“注册过程”中有一个步骤,我不再需要它,但我没有时间重新配置整个过程,所以我尝试在页面加载时自动提交表单,所以它基本上会跳过这个步。有什么想法吗?
EDIT: Sorry, I should mention, originally there were two submit options, I got rid of one, now I just want to submit the 'mem_type' option on page load. not sure if that makes much of a difference.
编辑:对不起,我应该提一下,最初有两个提交选项,我去掉了一个,现在我只想在页面加载时提交 'mem_type' 选项。不知道这是否有很大的不同。
<form method=post action="<?=$base_href.url("signup")?>" name="member_signup">
<input type=hidden name="process" value="facility_info">
<input type=hidden name="create_order" value="true">
<?php
foreach ($_POST as $k=>$d) {
if ($k === 'textarea') continue;
echo "<input type=hidden name=\"".strip_tags($k)."\" value=\"".strip_tags($d)."\">";
}
?>
<input type="submit" value="submit" name="mem_type" border="0">
</form>
回答by Anoop
Try this On window load submit your form.
试试这个 On window load 提交你的表单。
window.onload = function(){
document.forms['member_signup'].submit();
}
回答by Bob Wood
You can submit any form automatically on page load simply by adding a snippet of javascript code to your body tag referencing the form name like this....
您可以在页面加载时自动提交任何表单,只需将一段 javascript 代码添加到您的 body 标记中,引用表单名称,如下所示......
<body onload="document.form1.submit()">
回答by Jijesh Cherrai
Add the following to Body
tag,
将以下内容添加到Body
标签中,
<body onload="document.forms['member_signup'].submit()">
and give name
attribute to your Form
.
并赋予name
你的Form
.
<form method="POST" action="" name="member_signup">