[英]How can I get quantity variable from user when subnmitting a form using JavaScript?
It's a PayPal Subscription Plan and unlike their old subscription plans that were HTML forms, these are JavaScript only.这是一个 PayPal 订阅计划,与他们旧的 HTML 表单订阅计划不同,它们只是 JavaScript。
The plan is set up with different pricing depending on quantity ordered, but PayPal doesn't give you any way of getting the user to submit quantity and just defaults to a quantity of 1. I can manually set the quantity in the script (shown below with quantity of 4) which works just fine but there's no point in having this sort of button if I need a different button for each quantity.该计划根据订购的数量设置了不同的定价,但 PayPal 没有给您任何让用户提交数量的方法,只是默认数量为 1。我可以在脚本中手动设置数量(如下所示)数量为 4) 效果很好,但是如果我需要为每个数量使用不同的按钮,那么使用这种按钮是没有意义的。
Here is the PayPal code with identifiers removed;这是删除了标识符的 PayPal 代码;
<div id="paypal-button-container"></div>
<script src="https://www.paypal.com/sdk/js?client-id=ABCD-ABC_1234ABCD&vault=true&intent=subscription" data-sdk-integration-source="button-factory"></script>
<script>
paypal.Buttons({
style: {
shape: 'rect',
color: 'gold',
layout: 'vertical',
label: 'subscribe'
},
createSubscription: function(data, actions) {
return actions.subscription.create({
'plan_id': 'P-123456789'
'quantity': '4'
});
},
onApprove: function(data, actions) {
alert(data.subscriptionID);
}
}).render('#paypal-button-container');
</script>
So what I need is a way to have the actual quantity dynamically updated by the user before they hit the Subscribe button.所以我需要的是一种让用户在点击订阅按钮之前动态更新实际数量的方法。 I assume this is possible via JS but I have no idea how.
我认为这可以通过 JS 实现,但我不知道如何实现。 The same question has been asked twice on the PayPal Community Website but no answers have yet been posted.
同样的问题在 PayPal 社区网站上已被问过两次,但尚未发布任何答案。
Create an HTML input or select dropdown that allows selecting the quantity.创建允许选择数量的 HTML 输入或选择下拉列表。 Simple example:
简单的例子:
<span>Qty: </span><input id="myQuantity" type="text" />
.... ....
createSubscription: function(data, actions) {
return actions.subscription.create({
'plan_id': 'P-123456789'
'quantity': document.getElementById('myQuantity').value
});
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.