开发者

Javascript automatic form submission

开发者 https://www.devze.com 2023-02-24 05:45 出处:网络
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.

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 na开发者_JAVA技巧me="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>


Ok, the problem is in this part : input name="submit" type="hidden" value="purchase".

Submit input has the same name as the form function. If you replace the name 'submit' by other name (submit1 as example) it should be working as a charm. :-)

Good luck.

0

精彩评论

暂无评论...
验证码 换一张
取 消