Reputation: 101553
I have a PayPal form as follows: (some fields are added using jQuery)
<form method="post" action="https://www.paypal.com/cgi-bin/webscr"> <input type="hidden" value="_s-xclick" name="cmd"> <input type="hidden" value="sdfgsdfg" name="hosted_button_id"> <input type="button" value="Purchase One Year License" name="submit" class="pp_button" id="35" style="background-color: rgb(255, 255, 255);"> <input type="hidden" value="35" name="cs_project_id"> <input type="hidden" value="6d04c7a241ad4415eb194a90dc252b09" name="cs_transaction_id"> </form>
I'm trying to submit the form using the 3rd input
element (type="button"
) using this code:
$(".pp_button").click(function() { var button = $(this); button.parent().submit(); });
This should work fine right? I'm using var button
because of other parts later in the click()
function. I've checked the tagName
of button.parent()
and it's given as FORM
, so that's fine...
What have I done wrong here? This usually works fine... Is it because I'm inserting tags (the last two input
tags) from an AJAX call? Something else? A lack of mature cheddar on my desk?
Thanks,
James
Upvotes: 2
Views: 4263
Reputation: 14061
Why don't you just set the input type from button
to submit
? This would make the button submit the form and not need any Javascript?
Or if you want to use javascript (jQuery), you could give the form an ID like this:
<form method="post" action="https://www.paypal.com/cgi-bin/webscr" id="paypal_form">
And when you want to submit the form you can call:
$("#paypal_form").submit();
Upvotes: 4
Reputation: 944568
You have a form control named submit
. This clobbers the submit
function with an HTMLElementNode
.
The best solution is probably to not use JavaScript here. You say that you need other things to happen, but the user might have JS turned off, so if they are important you would almost certainly be better off finding a different way.
The simple solution is to change the name.
The complicated solution would be to get a copy of the submit method from another form, then use it with the form you want to submit:
document.createElement('form').submit.apply(this.form);
Upvotes: 3