简体   繁体   English

在贝宝中获取动态商品名称立即购买按钮

[英]get dynamic item name in paypal buy now button

Please see this screenshot below: 请在下面查看此屏幕截图:

http://i.stack.imgur.com/feZvR.png http://i.stack.imgur.com/feZvR.png

This is my form with a dropdown of 25 items in it. 这是我的表格,里面有25个项目的下拉列表。

The price for all the items are same so no worries about the price. 所有商品的价格均相同,因此无需担心价格。

But the name of all the products are different. 但是所有产品的名称都不同。

I am facing difficulty in getting the Item Name dynamically in buy now button. 我现在很难在“立即购买”按钮中动态获取商品名称。

<input type="hidden" id="item_name" name="item_name" value="">

Whenever user selects any option from dropdown, value="" must set with selected item's value and than go to paypal payment page (in php code or js code, anyone can do). 每当用户从下拉菜单中选择任何选项时,value =“”必须设置所选项目的值,然后转到Paypal付款页面(在php代码或js代码中,任何人都可以做)。

Can anyone suggest how to get this value dynamically? 谁能建议如何动态获取此值?

Assuming you only want to have one "buy now" button: 假设您只想拥有一个“立即购买”按钮:

That should be doable with jQuery . 那应该可以用jQuery

$(document).ready(function() {
    $('yourSelector').change(function() {
        $('#item_name').val($('yourSelector').text());
    });
});

replace 'yourSelector' with the id of your dropdown-menu. 将“ yourSelector”替换为下拉菜单的ID。 You could also do it with native javascript, though. 您也可以使用本机javascript来做到这一点。

You could store the name and the value in a array. 您可以将名称和值存储在数组中。 Then in a foreach() loop echo out all items like so: 然后在foreach()循环中回显所有项目,如下所示:

<?php

$items = [
    'item1' => 'value1',
    'item2' => 'value2',
    'item3' => 'value3'
];

foreach ($items as $item => $value) {
    echo '<input type="hidden" id="' . $item . '" name="' . $item . '" value="' . $value . '">';
}

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM