Javascript自动表单提交 [英] Javascript automatic form submission
问题描述
我从StackOverflow的另一篇文章中看到了这个快速脚本,但它似乎不适用于我的表单。它只是抛出一个错误,说'对象预期'。任何人都可以帮我解决它。
< html>
< head>< / head>
< body onLoad =document.forms [0] .submit()>
< form name =EPDQFormmethod =postaction =mypage.aspx>
< input name =itemtype =hiddenvalue =data>
< / form>
< / body>
< / html>
编辑:
页面代码(我删除了大部分内容以显示在这里):
< html>< head>< / head> ;
< body onLoad =document.forms [0] .submit()>
< input name =epdqdatatype =hiddenvalue =972>
< input name =returnurltype =hiddenvalue =http://www.xxxx.co.uk/Secure/EPDQReturn.aspx>
< input name =merchantdisplaynametype =hiddenvalue =xxxxxx>
< input name =submittype =hiddenvalue =purchase>
< input name =shippingtype =hiddenvalue =0.00>
< input name =baddr1type =hiddenvalue =152 Smith St>
< input name =baddr2type =hiddenvalue =>
< input name =bcitytype =hiddenvalue =Manchester>
< input name =bcountrytype =hiddenvalue =UK>
< input name =bpostalcodetype =hiddenvalue =M4 6DH>
< input name =emailtype =hiddenvalue =xxxx@xxxx.co.uk>
< input name =saddr1type =hiddenvalue =152 Smith St>
< input name =scitytype =hiddenvalue =Manchester>
< input name =scountyprovincetype =hiddenvalue =Alderney>
< input name =scountrytype =hiddenvalue =UK>
< input name =spostalcodetype =hiddenvalue =M4 5GG>
< / form>< / body>< / html>
此代码显示错误。我不明白为什么。在firefox中它说:
pre $ document.forms [0] .submit不是函数
$ c $如果您删除了 onload
,那么会发生什么? 属性从你打开的< body>
标记中,并将这个代码放在关闭< / body>
标记之前?
< script>
var frm = document.getElementById('myform');
if(frm){
frm.submit();
}
< / script>
I took this quick script from another post on StackOverflow, but it doesn't seem to work on my form. It just throws an error saying 'object expected'. Can anyone help me fix it.
<html>
<head></head>
<body onLoad="document.forms[0].submit()">
<form name="EPDQForm" method="post" action="mypage.aspx" >
<input name="item" type="hidden" value="data">
</form>
</body>
</html>
EDIT:
This is the exact page code (I removed most of it for displaying on here):
<html><head></head>
<body onLoad="document.forms[0].submit()">
<form id="myform" name="myform" method="post" action="https://secure2.mde.epdq.co.uk/cgi-bin/CcxBarclaysEpdq.e" >
<input name="epdqdata" type="hidden" value="972">
<input name="returnurl" type="hidden" value="http://www.xxxx.co.uk/Secure/EPDQReturn.aspx">
<input name="merchantdisplayname" type="hidden" value="xxxxxx">
<input name="submit" type="hidden" value="purchase">
<input name="shipping" type="hidden" value="0.00">
<input name="baddr1" type="hidden" value="152 Smith St">
<input name="baddr2" type="hidden" value="">
<input name="bcity" type="hidden" value="Manchester">
<input name="bcountry" type="hidden" value="UK">
<input name="bpostalcode" type="hidden" value="M4 6DH">
<input name="email" type="hidden" value="xxxx@xxxx.co.uk">
<input name="saddr1" type="hidden" value="152 Smith St">
<input name="scity" type="hidden" value="Manchester">
<input name="scountyprovince" type="hidden" value="Alderney">
<input name="scountry" type="hidden" value="UK">
<input name="spostalcode" type="hidden" value="M4 5GG">
</form></body></html>
This code shows the error. And I don't see why. In firefox it says:
document.forms[0].submit is not a function
What happens if you remove the onload
attribute from your opening <body>
tag and place this code just before your closing </body>
tag?
<script>
var frm = document.getElementById('myform');
if (frm) {
frm.submit();
}
</script>
这篇关于Javascript自动表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!