我一直在阅读有关如何使用PayPal表单的内容。我已经创建了一个使用选项的表单,但是我希望能够在两个下拉框之间进行切换,具体取决于它们是选择选项A还是选择选项B ...
(我发现距离很近的唯一问题是-Creating Multiple Select Option Box in Paypal Shopping Cart-我不理解。)
这是一些示例代码:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" data-abide>
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="bn" value="MRobertsDesign_BuyNow_WPS_CA">
<input type='hidden' name='lc' value='CA'>
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="return" value="http://mrobertsdesign.ca/design/payments/completed/">
<input type="hidden" name="cancel_return" value="http://mrobertsdesign.ca/design/payments/cancelled/">
<input type="hidden" name="item_number" value="service-plan">
<input type="text" placeholder="What is your name?" id="pack_name" name="os1" maxlength="100">
<select id="pack_type" name="item_name">
<option value="">Choose a plan:</option>
<option value="Basic">Basic - Starting at $90</option>
<option value="Advanced">Advanced - Starting at $190</option>
</select>
<!-- Options A (Basic) -->
<select id="pack_time" name="os0">
<option value="">Choose your hours:</option>
<option value="2hrs">2 Hours - $90.00</option>
<option value="3hrs">3 Hours - $180.00</option>
<option value="4hrs">4 Hours - $228.00</option>
</select>
<input type="hidden" name="option_select0" value="2hrs">
<input type="hidden" name="option_amount0" value="90.00">
<input type="hidden" name="option_select1" value="3hrs">
<input type="hidden" name="option_amount1" value="180.00">
<input type="hidden" name="option_select2" value="4hrs">
<input type="hidden" name="option_amount2" value="228.00">
<!-- Options B (Advanced) -->
<select id="pack_time" name="os0">
<option value="">Choose your hours:</option>
<option value="2hrs">2 Hours - $190.00</option>
<option value="3hrs">3 Hours - $240.00</option>
<option value="4hrs">4 Hours - $328.00</option>
</select>
<input type="hidden" name="option_select0" value="2hrs">
<input type="hidden" name="option_amount0" value="190.00">
<input type="hidden" name="option_select1" value="3hrs">
<input type="hidden" name="option_amount1" value="240.00">
<input type="hidden" name="option_select2" value="4hrs">
<input type="hidden" name="option_amount2" value="328.00">
<input type="hidden" name="on1" value="Client">
<input type="hidden" name="on0" value="Hours">
<input type="submit" name="submit" class="button radius payments-buy" value="Buy Now">
</form>
这个想法是,当有人选择基本或高级时:
<select id="pack_type" name="item_name">
<option value="">Choose a plan:</option>
<option value="Basic">Basic - Starting at $90</option>
<option value="Advanced">Advanced - Starting at $190</option>
</select>
它将下拉菜单分别更改为A或B。
现在我不确定该怎么做,有人有什么想法吗?我不确定您是否了解我在做什么,但是请问我是否需要更多说明,我不确定我还能说什么。
我对PHP有了更多的了解,所以我明白了...当某人单击该下拉框并选择Basic或Advance时,它需要触发一个jQuery脚本,该脚本将首先进行检查以查看被单击的内容,然后循环浏览数组中的值并填充表单。我只是不知道该怎么做,有人要试一试吗?
为了举例说明,我非常想获得此psuedo-php代码的JS / jQuery版本:
<select id="pack_type" name="item_name">
<option value="">Choose a plan:</option>
<option value="Basic">Basic - Starting at $90</option>
<option value="Advanced">Advanced - Starting at $190</option>
</select>
<?php
// I know this doesn't work but for the sake of example
if (select.pack_type option.basic.selected) {
var $pack_type = 'basic';
} elseif (select.pack_type option.advanced.selected) {
var $pack_type = 'advanced';
} else {
var $pack_type = NULL;
}
// Basic
$plan['basic'][] = array(
'hours' => '2 Hours',
'price' => '90.00',
);
$plan['basic'][] = array(
'hours' => '3 Hours',
'price' => '120.00',
);
$plan['basic'][] = array(
'hours' => '4 Hours',
'price' => '250.00',
);
// Advanced
$plan['advanced'][] = array(
'hours' => '2 Hours',
'price' => '190.00',
);
$plan['advanced'][] = array(
'hours' => '3 Hours',
'price' => '220.00',
);
$plan['advanced'][] = array(
'hours' => '4 Hours',
'price' => '350.00',
);
// Other variables
$i = 0;
if ($pack_type == 'basic') {
// Echo basic
echo '<select id="pack_time" name="os1"><option value="">Choose your hours:</option>';
foreach ($plan['basic'] as $prices) {
echo '<option value="' . $prices['hours'] . '">' . $prices['hours'] . ' - $' . $prices['price'] . '</option>';
}
echo '</select>';
foreach ($plan['basic'] as $prices) {
echo '<input type="hidden" name="option_select' . $i++ . '" value="' . $prices['hours'] . '"><input type="hidden" name="option_amount' . $i++ . '" value="' . $prices['price'] . '">';
}
} elseif ($pack_type == 'advanced') {
// Echo advanced
echo '<select id="pack_time" name="os1"><option value="">Choose your hours:</option>';
foreach ($plan['advanced'] as $prices) {
echo '<option value="' . $prices['hours'] . '">' . $prices['hours'] . ' - $' . $prices['price'] . '</option>';
}
echo '</select>';
foreach ($plan['advanced'] as $prices) {
echo '<input type="hidden" name="option_select' . $i++ . '" value="' . $prices['hours'] . '"><input type="hidden" name="option_amount' . $i++ . '" value="' . $prices['price'] . '">';
}
} else {
// Echo nothing
echo '<select id="pack_time" name="os1"><option value="">Choose your hours:</option></select>';
}
?>
最佳答案
贝宝(Paypal)使您可以选择具有不同价格的产品下拉菜单。
登录到贝宝。
转到个人资料,选择“我的销售工具”
点击“管理我的付款按钮”旁边的更新。
创建一个新按钮
选中“使用价格/选项添加下拉菜单”复选框
然后您将获得一个屏幕,如下图所示。
添加:这是一个jsfiddle,它可能会帮助您尝试实现的目标。下拉菜单,选择后将显示和隐藏单独的按钮。
jQuery的
$('select.div-toggler').change(function(){
var target = $(this).data('target');
$(target).children().addClass('hide');
var show = $("option:selected", this).data('show');
$(show).removeClass('hide');
});
http://jsfiddle.net/TLBvx/61/
关于jquery - Paypal :在多个选项框之间切换?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30364026/