2015-08-27 60 views
0

我試圖將派生的總數傳遞給paypal捐贈按鈕(非託管按鈕),但PayPal仍然顯示0.我嘗試了一切,我在這個網站上閱讀,但仍然couldn不要讓它工作。任何幫助表示讚賞。傳遞可變金額給PayPal捐贈按鈕不起作用

這是我的腳本。

function isNumberKey(evt) { 
    var charCode = (evt.which) ? evt.which : evt.keyCode; 
    if (charCode != 46 && charCode > 31 
     && (charCode < 48 || charCode > 57)) 
     return false; 

    return true; 
} 

function sum() { 
    var txtPKDValue = document.getElementById('txtPKD').value; 
    var txtHeartValue = document.getElementById('txtHeart').value; 
    var txtAlzheimerValue = document.getElementById('txtAlzheimer').value; 
    var txtDiabetesValue = document.getElementById('txtDiabetes').value; 
    var txtStridesValue = document.getElementById('txtStrides').value; 
    var txtNightWalkValue = document.getElementById('txtNightWalk').value; 
    var txtJingleValue = document.getElementById('txtJingle').value; 
    var txtMSValue = document.getElementById('txtMS').value; 
    var txtDimesValue = document.getElementById('txtDimes').value; 
    var txtStepsValue = document.getElementById('txtSteps').value; 
    var txtUnspecifiedValue = document.getElementById('txtUnspecified').value; 

    if (txtPKDValue == "") 
     txtPKDValue = 0; 
    if (txtHeartValue == "") 
     txtHeartValue = 0; 
    if (txtAlzheimerValue == "") 
     txtAlzheimerValue = 0; 
    if (txtDiabetesValue == "") 
     txtDiabetesValue = 0; 
    if (txtStridesValue == "") 
     txtStridesValue = 0; 
    if (txtNightWalkValue == "") 
     txtNightWalkValue = 0; 
    if (txtJingleValue == "") 
     txtJingleValue = 0; 
    if (txtMSValue == "") 
     txtMSValue = 0; 
    if (txtDimesValue == "") 
     txtDimesValue = 0; 
    if (txtStepsValue == "") 
     txtStepsValue = 0; 
    if (txtUnspecifiedValue == "") 
     txtUnspecifiedValue = 0; 

    var result = parseInt(txtPKDValue) + parseInt(txtHeartValue) + parseInt(txtAlzheimerValue) + 
     parseInt(txtDiabetesValue) + parseInt(txtStridesValue) + parseInt(txtNightWalkValue) + parseInt(txtJingleValue) + parseInt(txtMSValue) + parseInt(txtDimesValue) 
     + parseInt(txtStepsValue) + parseInt(txtUnspecifiedValue); 
    if (!isNaN(result)) { 
     document.getElementById('txtTotal').value = result; 
    } 
} 
<table width="100%"> 
    <tr> 
    <td align="center"> 
     <fieldset> 
     <legend><strong>Donations</strong></legend> 
     <table width="35%"> 
      <tr> 
      <td><strong>Name</strong></td> 
      <td>:</td> 
      <td> 
       <input id="txtName" type="text" /></td> 
      </tr> 
      <tr> 
      <td style="font-weight: 700">E-Mail</td> 
      <td>:</td> 
      <td> 
       <input id="txtMail" type="text" /></td> 
      </tr> 
      <tr> 
      <td> 
       <label class="wsite-form-label" for="input-709251636882788888"> 
       Sacramento Walk for PKD <span class="form-not-required">*</span></label> 
      </td> 
      <td>:</td> 
      <td> 
       <input id="txtPKD" type="text" onkeyup="sum()" onkeypress="return isNumberKey(event)" /></td> 
      </tr> 
      <tr> 
      <td> 
       <label class="wsite-form-label" for="input-580604488995192577"> 
       Heart Walk <span class="form-not-required">*</span></label> 
      </td> 
      <td>:</td> 
      <td> 
       <input id="txtHeart" type="text" onkeyup="sum()" onkeypress="return isNumberKey(event)" /></td> 
      </tr> 
      <tr> 
      <td> 
       <label class="wsite-form-label" for="input-543781094323884944"> 
       Walk to End Alzheimer&#39;s <span class="form-not-required">*</span></label> 
      </td> 
      <td>:</td> 
      <td> 
       <input id="txtAlzheimer" type="text" onkeyup="sum()" onkeypress="return isNumberKey(event)" /></td> 
      </tr> 
      <tr> 
      <td> 
       <label class="wsite-form-label" for="input-150817808255225992"> 
       Walk to Cure Diabetes <span class="form-not-required">*</span></label> 
      </td> 
      <td>:</td> 
      <td> 
       <input id="txtDiabetes" type="text" onkeyup="sum()" onkeypress="return isNumberKey(event)" /></td> 
      </tr> 
      <tr> 
      <td> 
       <label class="wsite-form-label" for="input-235351783434196510"> 
       Making Strides of Sacramento <span class="form-not-required">*</span></label> 
      </td> 
      <td>:</td> 
      <td> 
       <input id="txtStrides" type="text" onkeyup="sum()" onkeypress="return isNumberKey(event)" /></td> 
      </tr> 
      <tr> 
      <td> 
       <label class="wsite-form-label" for="input-304111226551762696"> 
       Light the Night Walk <span class="form-not-required">*</span></label> 
      </td> 
      <td>:</td> 
      <td> 
       <input id="txtNightWalk" type="text" onkeyup="sum()" onkeypress="return isNumberKey(event)" /></td> 
      </tr> 
      <tr> 
      <td> 
       <label class="wsite-form-label" for="input-304111226551762696"> 
       Jingle Bell Run/Walk <span class="form-not-required">*</span></label> 
      </td> 
      <td>:</td> 
      <td> 
       <input id="txtJingle" type="text" onkeyup="sum()" onkeypress="return isNumberKey(event)" /></td> 
      </tr> 
      <tr> 
      <td> 
       <label class="wsite-form-label" for="input-478476217892767991"> 
       Walk MS <span class="form-not-required">*</span></label> 
      </td> 
      <td>:</td> 
      <td> 
       <input id="txtMS" type="text" onkeyup="sum()" onkeypress="return isNumberKey(event)" /></td> 
      </tr> 
      <tr> 
      <td> 
       <label class="wsite-form-label" for="input-843779283694541422"> 
       March of Dimes <span class="form-not-required">*</span></label> 
      </td> 
      <td>:</td> 
      <td> 
       <input id="txtDimes" type="text" onkeyup="sum()" onkeypress="return isNumberKey(event)" /></td> 
      </tr> 
      <tr> 
      <td> 
       <label class="wsite-form-label" for="input-843779283694541422"> 
       <label class="wsite-form-label" for="input-229220521676593435"> 
        Take Steps 
       </label> 
       </label> 
      </td> 
      <td>:</td> 
      <td> 
       <input id="txtSteps" type="text" onkeyup="sum()" onkeypress="return isNumberKey(event)" /></td> 
      </tr> 
      <tr> 
      <td> 
       <strong>Unspecified</strong></td> 
      <td>:</td> 
      <td> 
       <input id="txtUnspecified" type="text" onkeyup="sum()" onkeypress="return isNumberKey(event)" /></td> 
      </tr> 
      <tr> 
      <td> 
       <label class="wsite-form-label" for="input-843779283694541422"> 
       Total Amount</label> 
      </td> 
      <td>:</td> 
      <td> 
       <input id="txtTotal" type="text" readonly="true" onkeypress="return isNumberKey(event)" /></td> 
      </tr> 
      <tr> 
      <td> 
       <label class="wsite-form-label" for="input-277539319803365071"> 
       Comments <span class="form-not-required">*</span></label> 
      </td> 
      <td>:</td> 
      <td> 
       <textarea rows="5" id="txtComment" cols="20"></textarea></td> 
      </tr> 
      <tr> 
      <td colspan="3" align="center"> 
     <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"> 
     <input type="hidden" name="cmd" value="_donations"> 
     <input type="hidden" name="business" value="XXXXXXXXXXXXX"> 
     <input type="hidden" name="lc" value="US"> 
     <input type="hidden" name="item_name" value="GFF"> 
     <input type="hidden" name="item_number" value="GFF2015"> 
     <input type="hidden" name="no_note" value="0"> 
     <input type="hidden" name="cn" value="Add special instructions to the seller:"> 
     <input type="hidden" name="no_shipping" value="1"> 
     <input type="hidden" name="currency_code" value="USD"> 
     <input type="hidden" name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHosted"> 
     <input type="hidden" name="amount" id="txtTotal" > 
     <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> 
     <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> 
     </form>  
      </td> 
      </tr> 
     </table> 
     </fieldset> 
    </td> 
    </tr> 
</table> 

回答

0

您有id=txtTotal兩種不同的元素。 ID必須是唯一的。任何代碼設置txtTotal的價值將只設置第一一個的發現 - 在這裏只讀版本:

<td> 
    <input id="txtTotal" type="text" readonly="true" onkeypress="return isNumberKey(event)" /> 
</td> 

消除這一行,你應該更好的形狀。或者給它一個新的ID,並在同時設置:

if (!isNaN(result)) { 
    document.getElementById('txtTotal').value = result; 
    document.getElementById('displayTxtTotal').value = result; 
}    
+0

非常感謝保羅。我創建了新的ID,它工作。 – SRK

相關問題