[英]How to pass value of item_name to Paypal page?
我有一個網頁,其中包含需要購買貝寶的產品。 我已經為該產品的各種選項使用了一個選擇框。
雖然我已經成功集成了貝寶,並且html頁面將“金額”傳遞給貝寶頁面。 我無法執行的操作是將與所選選項相對應的“ item_name”傳遞給貝寶頁面。
非常感謝您的任何幫助,謝謝。
<form name="" action="shop_paypal.php" method="post">
<input name="cmd" type="hidden" value="_xclick" />
<input name="no_note" type="hidden" value="1" />
<input name="lc" type="hidden" value="UK" />
<input name="currency_code" type="hidden" value="USD" />
<input name="bn" type="hidden" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHostedGuest" />
<div class="price-bottom-box">
<!--<input type="text" name="item_name" id="item_name"value="20,000 PINS" hidden="true"/>-->
<select name="amount" id="amount" style="width:256px; height:32px;">
<option value="18" id="1">10,000 PINS - $18 </option>
<option value="35" id="2">20,000 PINS - $35</option>
<option value="75" id="3">30,000 PINS - $75</option>
<option value="140" id="4">50,000 PINS - $140</option>
</select>
<input type = "image" value = "submtbtn" name = "submtbtn" src="images/buy-now-normal-bg.jpg" id="Image1">
</form>
注意 :我認為不確保您先了解一點是不道德的:很有可能發送'shop_paypal.php' 任何數值。 請不要信任作為“金額”發送的值。 您應該使用作為item_name(甚至更好的item_id)傳遞的值,並查找與請求的項目相對應的值。
現在如何執行看似不安全的方法:
替換您的代碼:
<!--<input type="text" name="item_name" id="item_name"value="20,000 PINS" hidden="true"/>-->
<select name="amount" id="amount" style="width:256px; height:32px;">
<option value="18" id="1">10,000 PINS - $18 </option>
<option value="35" id="2">20,000 PINS - $35</option>
<option value="75" id="3">30,000 PINS - $75</option>
<option value="140" id="4">50,000 PINS - $140</option>
</select>
有了這個:
<select id="item_name" name="item_name" style="width:256px; height:32px;"></select>
<input id="amount" name="amount" type="hidden" value=""/>
<script>
var items = [
{ name: "10,000 PINS", amount: 18 },
{ name: "20,000 PINS", amount: 35 },
{ name: "30,000 PINS", amount: 75 },
{ name: "50,000 PINS", amount: 140 }
];
var itemNameElement = document.getElementById("item_name");
itemNameElement.onchange = (function(){
var amount = items[this.selectedIndex].amount;
document.getElementById("amount").value = amount;
}).bind(itemNameElement);
document.getElementById("amount").value = items[0].amount;
for(var i=0; i<items.length; i++){
var item = document.createElement("option");
item.value = items[i].name;
item.text = items[i].name+" - $"+items[i].amount;
itemNameElement.add(item);
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.