我正在尝试将可变金额(这是订单总价值)传递给贝宝表单中的“金额”变量。但是,该值是从下拉列表中生成的。我浏览了论坛并尝试了一些方法,但找不到我认为简单的解决方案。
下面是代码。
正如您所看到的,我尝试了几个选项,但都没有传递从下拉列表中选择的变量。
我很欣赏 Paypal 的安全问题……但除此之外,是否有人比我有更大的大脑,可以找到明显的解决方案。
谢谢!!
Andy
PS 如果我将 var 'andy' 更改为 33,一切都会正常。
<label for="CurrentExcess">Current Excess (£100 - £500 Max.)</label>
<select id="dropdown">
<option value="invalid entry">please select</option>
<option value="12">£100</option>
<option value="18">£150</option>
<option value="24">£200</option>
<option value="30">£250</option>
<option value="36">£300</option>
<option value="42">£350</option>
<option value="48">£400</option>
<option value="54">£450</option>
<option value="60">£500</option>
<option value="all us to discuss">more then £500</option>
</select>
</div>
<div>
<label for="price">Your membership fee will be: £</label>
<input type="text" name="price" value="" id="mytext" />
<script type="text/javascript">
var mytextbox = document.getElementById('mytext');
var mydropdown = document.getElementById('dropdown');
mydropdown.onchange = function(){
mytextbox.value = this.value;
}
document.getElementById("finalpaypal").value = mytext;
var andy = mytext
</script>
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="item_name" value="My Title">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="item_number" value="11">
<!-- <script>
document.write('<input type="hidden" name="amount" value='+andy+'>');
</script> -->
<input type="hidden" name="amount" id="finalpaypal">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="add" value="1">
</form>
</body>
</html>
更新:感谢 sdleihssirhc 的输入。这确实有帮助,但由于我对 javascript 有点不懂,所以我仍然在挣扎。
我没有强调的一点是,我试图将“mytext”中的值获取到传递给贝宝的“金额”中。我不关心如何,但似乎该值是用“OnChange”计算的......这一切都有点疯狂。
代码的主要部分现在如下所示在帖子的最后一点。
任何人的任何好主意。非常感谢!!!!
<label for="CurrentExcess">Current Excess (£100 - £500 Max.)</label>
<select id="dropdown">
<option value="invalid entry">please select</option>
<option value="12">£100</option>
<option value="18">£150</option>
<option value="24">£200</option>
<option value="30">£250</option>
<option value="36">£300</option>
<option value="42">£350</option>
<option value="48">£400</option>
<option value="54">£450</option>
<option value="60">£500</option>
<option value="all us to discuss">more then £500</option>
</select>
</div>
<div>
<label for="price">Your membership fee will be: £</label>
<input type="text" name="price" value="" id="mytext" />
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="item_name" value="My Title">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="item_number" value="11">
<input type="hidden" name="amount" id="finalpaypal">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="add" value="1">
</form>
<script>
var mytextbox = document.getElementById('mytext');
var mydropdown = document.getElementById('dropdown');
var finalpaypal = document.getElementById('finalpaypal');
mydropdown.onchange = function(){
mytextbox.value = this.value;
finalpaypal.value = this.value;
}
document.getElementById("finalpaypal").value = mytext;
</script>
</body>
</html>
I am trying to pass a variable amount (this being the total order value) to the 'amount' variable in a paypal form. However, the value is generated from a drop down list. I've scoured the forums and tried a few things, but can't find what I thought would be a simple solution.
Below is the code.
As you can see there are a couple of options I have tried, but neither pass the variable selected from the drop down list.
I appreciate the issues with Paypal security... but that aside, is there anyone with a much larger brain than mine who can spot an obvious solution.
Thanks!!
Andy
PS If I change the var 'andy' to, say, 33, it all works fine.
<label for="CurrentExcess">Current Excess (£100 - £500 Max.)</label>
<select id="dropdown">
<option value="invalid entry">please select</option>
<option value="12">£100</option>
<option value="18">£150</option>
<option value="24">£200</option>
<option value="30">£250</option>
<option value="36">£300</option>
<option value="42">£350</option>
<option value="48">£400</option>
<option value="54">£450</option>
<option value="60">£500</option>
<option value="all us to discuss">more then £500</option>
</select>
</div>
<div>
<label for="price">Your membership fee will be: £</label>
<input type="text" name="price" value="" id="mytext" />
<script type="text/javascript">
var mytextbox = document.getElementById('mytext');
var mydropdown = document.getElementById('dropdown');
mydropdown.onchange = function(){
mytextbox.value = this.value;
}
document.getElementById("finalpaypal").value = mytext;
var andy = mytext
</script>
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="item_name" value="My Title">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="item_number" value="11">
<!-- <script>
document.write('<input type="hidden" name="amount" value='+andy+'>');
</script> -->
<input type="hidden" name="amount" id="finalpaypal">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="add" value="1">
</form>
</body>
</html>
UPDATE: Thanks for the input from sdleihssirhc. That does help, but as I am a bit of a duffer with javascript am still struggling.
The bit I didn't emphasise is that I am trying to get the value from 'mytext' into 'amount' which is passed to paypal. And I dont care how, but it seems that as the value is calculated with an 'OnChange'....it all goes a bit bonkers.
The main bits of code now read as below on last bit of post.
ANY BRIGHT IDEAS ANYONE. MANY THANKS!!!!
<label for="CurrentExcess">Current Excess (£100 - £500 Max.)</label>
<select id="dropdown">
<option value="invalid entry">please select</option>
<option value="12">£100</option>
<option value="18">£150</option>
<option value="24">£200</option>
<option value="30">£250</option>
<option value="36">£300</option>
<option value="42">£350</option>
<option value="48">£400</option>
<option value="54">£450</option>
<option value="60">£500</option>
<option value="all us to discuss">more then £500</option>
</select>
</div>
<div>
<label for="price">Your membership fee will be: £</label>
<input type="text" name="price" value="" id="mytext" />
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="item_name" value="My Title">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="item_number" value="11">
<input type="hidden" name="amount" id="finalpaypal">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="add" value="1">
</form>
<script>
var mytextbox = document.getElementById('mytext');
var mydropdown = document.getElementById('dropdown');
var finalpaypal = document.getElementById('finalpaypal');
mydropdown.onchange = function(){
mytextbox.value = this.value;
finalpaypal.value = this.value;
}
document.getElementById("finalpaypal").value = mytext;
</script>
</body>
</html>
发布评论
评论(2)
我认为第一个问题是你的 HTML - JavaScript - HTML 排序。你的 JS 中有这一行...
...但是 ID 为“finalpaypal”的元素还不存在。您能否将
移至页面底部(位于所有表单的 HTML 之后)?
第二个问题也与该行有关。您试图将输入的值设置为一个(据我所知)实际上并不存在的变量。如果您希望该值与您在文本框中设置的值相同,只需执行以下操作:
但是我们遇到了最后一个问题:您应该将此行放在事件处理程序中。
所以最终的代码将如下所示:
I think the first problem is with the your HTML - JavaScript - HTML ordering. You have this line in your JS...
...But the element with the ID "finalpaypal" doesn't exist, yet. Can you move the
<script>
to the bottom of the page, after all of the form's HTML?The second problem is also with that line. You're trying to set the input's value to a variable that (as far as I can tell) doesn't actually exist. If you want the value to be the same as what you set the textbox to, just do this:
But then we get to the last problem: You should put this line inside the event handler.
So the final code will look like this:
为了使用
select
标签,您必须将其包含在您的 paypal 按钮表单中。您必须使用on0
和os0
标记。您可以在这里阅读更多相关信息:单击此处
您可以在此处查看示例:点击此处
href="https://developer.paypal.com/webapps/developer/docs/classic/paypal- payments- standard/integration-guide/paypal_shopping_cart/#id08AEC03L05H jsfiddle 示例就在这里
In order to use the
select
tag you have to include it in your paypal button form. You have to use theon0
andos0
tags.You can read more about it here: click here
and you can see examples here: click here
and a jsfiddle example for you right here