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="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
fjaxyu
3901 gold badge3 silver badges10 bronze badges
asked Apr 12, 2011 at 11:40

2 Answers 2

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>
answered Apr 12, 2011 at 13:09
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, the script is executing BEFORE the HTML is fully loaded.
What if we need to send cookies along the form to make it work?\
1

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.

answered Apr 12, 2011 at 11:56

2 Comments

I've updated the question to show my actual full code. This code reproduces the error.
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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.