2011-03-11 61 views
2

我有一個貝寶的形式如下:(某些字段使用jQuery加)提交使用貝寶JS形式不工作

 
<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> 

我試圖使用使用第三input元素(type="button")提交表單驗證碼:

 
$(".pp_button").click(function() 
{ 
    var button = $(this); 
    button.parent().submit(); 
}); 

這應該很好地工作吧?由於click()函數後面的其他部分,我正在使用var button。我檢查了button.parent()tagName,它的編號爲FORM,所以這很好...

我在這裏做了什麼錯?這通常工作正常...是因爲我從AJAX調用插入標籤(最後兩個input標籤)?還有別的嗎?我的桌子上缺乏成熟的切達乾酪?

感謝,

詹姆斯

回答

4

你爲什麼不只是設置的輸入類型從buttonsubmit?這會使按鈕提交表單而不需要任何Javascript?

或者,如果你想使用JavaScript(jQuery的),你能給形式像這樣的ID:

<form method="post" action="https://www.paypal.com/cgi-bin/webscr" id="paypal_form"> 

而當你想提交表單,您可以撥打:

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

您有一個名爲submit表單控件。這個submit功能與HTMLElementNode

最好的解決方案可能是在這裏不使用JavaScript。你說你需要其他的事情發生,但用戶可能會關閉JS,所以如果他們很重要,你幾乎肯定會找到一種不同的方式更好。

簡單的解決方案是更改名稱。

這個複雜的解決辦法是從另一種形式得到提交方法的副本,然後用形式使用它,你要提交:

document.createElement('form').submit.apply(this.form); 
+0

令人煩惱的是我不能改變名字(至少我認爲);它可能會以某種方式被PayPal使用......我會用另一個名字來測試它。 – Bojangles 2011-03-11 15:23:58

+0

Yeaop ...我收到一個錯誤:-(Dang。 – Bojangles 2011-03-11 15:24:41