8

This is the code that isn't working:

<form id="paypal" name="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_parent" />Official website!
    <input type="hidden" name="item_name" value="Donation">
    <input type="hidden" name="cmd" value="_donations">
    <input type="hidden" name="bn" value="PP-DonationsBF">
    <input type="hidden" name="currency_code" id="currency_code" value="GBP" >
    <input type="hidden" name="business" id="business" value="[email protected]" >

    <a href="javascript: donate(paypal);" class="button1"><span></span><strong>£<input name="amount" type="text" id="ppAmount" style="text-align:center;" value="5" size="2" /> Donate!</strong></a>

    <input type="submit">
</form>

<div id="formtesting"></div>

<script type="text/javascript">

function donate(paypal) {
    document.getElementById("formtesting").innerHTML="maybe...";
    document.forms["paypal"].action = "https://www.paypal.com/cgi-bin/webscr";
    document.forms["paypal"].submit();
    document.getElementById("formtesting").innerHTML="did it work?";
}

</script>

I want it to submit when clicking on "button1", using "javascript: donate(paypal)" the submit button works fine.. (it prints "maybe" in the formtesting div but not "did it work?" :/)

2
  • 1
    As far as I know, I don't think that any code after submit() will execute. Please do correct me if I'm mistaken Commented Mar 12, 2012 at 10:09
  • 1
    Is it a typo or your <form> tag is really closed in the first line of this code snippet? Commented Mar 12, 2012 at 10:11

5 Answers 5

41

I ran into the issue of myForm.submit() was not submitting the form. Turns out that my problem was that my submit button's id was 'submit'. Once I changed my id to another name, viola, it worked. Hopefully this helps someone else out there who's run into this same variation of this problem.

EDIT: Also make note of MalcomOcean's comment, below, where the name tag can also cause this issue

Sign up to request clarification or add additional context in comments.

6 Comments

THANK YOU. Though in my case it was the name of the submit button, not the id.
You save my day!
IF you using form.dispatchEvent( new Event( 'submit' ) ); instead of form.submit() form item named 'submit' will not be problem anymore.
wow... just wow
This has helped me too, despite the fact that i have several AIs to support...
|
5

Use this code it will work

function donate() {
document.getElementById("formtesting").innerHTML="maybe...";
document.paypal.action = "https://www.paypal.com/cgi-bin/webscr";
document.paypal.submit();
document.getElementById("formtesting").innerHTML="did it work?";
}

Here paypal is name of the form.

3 Comments

in which browser you are using?
Could you please explain why document.paypal works whereas document["paypal"] does not?
document.forms is an array. So document.forms["paypal"] doesn't make sense because array needs index number, not a string.
3

Faced the same issue, submit from javascript was not submitting the form. Tried all ways of submitting form from javascript like document.formname.submit() OR document.getElementById("formId").submit(). But these didnt work.

The problem was in my html page, there was another button (not the one I was clicking) and name of that button was "submit". When i changed that name to something else, my form was getting submitted.

Comments

0

For me, this was caused by trying to access elements that don't exist. Even viewing in the developer console, there will be no error log notice, but the code will abort. My code:

function MoveImageUp(id)
{
    document.fms.aid.value= id;
    document.fms.mode.value='up'; // die! the form has no element called aid

    document.fms.submit();
}

Double check all referenced elements.

Comments

0

Remove all "<" form ">" open and close tags and if you are using document.createElement("form");

Comments

Your Answer

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.