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

javascript - Submit PayPal form using JS not working - Stack Overflow

programmeradmin0浏览0评论

I have a PayPal form as follows: (some fields are added using jQuery)

<form method="post" action="">
    <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

I have a PayPal form as follows: (some fields are added using jQuery)

<form method="post" action="https://www.paypal./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

Share Improve this question asked Mar 11, 2011 at 15:12 BojanglesBojangles 102k50 gold badges174 silver badges209 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 4

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./cgi-bin/webscr" id="paypal_form">

And when you want to submit the form you can call:

$("#paypal_form").submit();

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 plicated 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);
发布评论

评论列表(0)

  1. 暂无评论