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="paypalemail@null.com" >
<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></span>
<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?";
}
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?" :/)
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:
Double check all referenced elements.
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.
I ran into the issue of
myForm.submit()
was not submitting the form. Turns out that my problem was that my submit button'sid
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 issueMake sure that you are using getElementById, not getElementByid .
Use this code it will work
Here paypal is name of the form.
This works: