以下是代码。 目标:将“数量”值替换为“点击”按钮,其中包含id =“rp_button6”的“re_valve”值中的值。
提取此值
<input type="text" class="form-control" id="re_valve">
启动按钮
<button type="button" class="btn btn-primary btn-flat" id="rp-button6">Pay Amount</button>
要插入值的脚本
<script>
var options = {
"key": "XXXXXXXXXXXX",
"amount": "2000", // 2000 paise = INR 20
"name": "<?php echo $m9['fname']; ?> <?php echo $m9['lname']; ?>",
"description": "Digital Server Renewal",
"image": "http://www.digitalocean.com/favicon/android-icon-192x192.png",
"handler": function (response){
$("#payment_gateway_stargate_2").html(response.rarpay_payment_id);
var rpid = response.rarpay_payment_id;
window.location = '/receipt.php?billno=' + rpid;
},
"prefill": {
"name": "<?php echo $m9['fname']; ?> <?php echo $m9['lname']; ?>",
"email": "<?php echo $m9['email']; ?>",
"contact": "<?php echo $m9['phone']; ?>"
},
"notes": {
"shopping_id": "<?php echo encrypt_ssc($_SESSION['user_id'].'_'.rand(999,9999)); ?>"
},
"theme": {
"color": "#F37254"
}
};
var rp6 = new Rarpay(options);
document.getElementById('rp-button6').onclick = function(e){
rp6.open();
e.preventDefault();
}
</script>
答案 0 :(得分:0)
从输入中获取值,然后将其分配给options
对象。
请注意,ZERO&#34;防守代码&#34;在这个例子中。 (意思是在依赖于获取它的值之前检查re_valve元素是否存在,在设置options.amount
之前检查document.getElementById('rp-button6').onclick = function(e) {
// get the value of the re_valve input
var amount = document.getElementById('re_valve').value;
// assign the value to the "amount" property of "options" object
options.amount = amount;
// note that the below would also work:
// options['amount'] = amount;
rp6.open();
e.preventDefault();
}
对象是否存在等)。
/root
/branches
/tags
/trunk
答案 1 :(得分:0)
document.getElementById('rp-button6').onclick = function(e) {
e.preventDefault();
options.value = document.getElementById('re_valve').value;
rp6.open();
}
答案 2 :(得分:0)
它取决于Rarpay()
对options
的作用 - 如果它仍然引用原文;
document.getElementById('rp-button6').onclick = function(e){
options.amount = document.getElementById('re_valve').value ;
rp6.open();
e.preventDefault();
}
否则(或在任何一种情况下)
document.getElementById('rp-button6').onclick = function(e){
options.amount = document.getElementById('re_valve').value ;
rp6 = new Rarpay(options);
rp6.open();
e.preventDefault();
}
(假设创建一个新的Rarpay
可以)