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

html - Javascript automatic form submission - Stack Overflow

programmeradmin1浏览0评论

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=".e">

            <input name="epdqdata" type="hidden" value="972">
            <input name="returnurl" type="hidden" value=".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="[email protected]">
            <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

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="[email protected]">
            <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
Share Improve this question edited Sep 18, 2018 at 20:05 fjaxyu 3901 gold badge3 silver badges10 bronze badges asked Apr 12, 2011 at 11:40 Grant UnwinGrant Unwin 3053 gold badges4 silver badges8 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 1

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)

  1. 暂无评论