Php 添加“立即购买”和“添加到购物车”按钮,只需一个下拉列表
我想添加一个立即购买按钮和添加到购物车按钮在同一表单上,只有一个下拉菜单。目前,我有两个下拉菜单,这是完全相同的,如果我想有立即购买和添加到购物车按钮 因此,基本上我只想使用一个下拉菜单的立即购买和添加到购物车按钮链接到这两个按钮 这是只用于“立即购买”按钮的htmlPhp 添加“立即购买”和“添加到购物车”按钮,只需一个下拉列表,php,html,forms,e-commerce,Php,Html,Forms,E Commerce,我想添加一个立即购买按钮和添加到购物车按钮在同一表单上,只有一个下拉菜单。目前,我有两个下拉菜单,这是完全相同的,如果我想有立即购买和添加到购物车按钮 因此,基本上我只想使用一个下拉菜单的立即购买和添加到购物车按钮链接到这两个按钮 这是只用于“立即购买”按钮的html <form id="form_35" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_self" style="margin:0;p
<form id="form_35" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_self" style="margin:0;position:absolute;left:492px;top:112px;width:199px;height:68px; /*MainDivStyle*/" __AddCode="here">
<!--MainDivStart-->
<input type="hidden" name="bn" value="Serif.WebPlus">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="info@mysite.com">
<input type="hidden" name="item_name" value="Polo Shirt">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="amount" value="20.00">
<input type="hidden" name="weight" value="0.18">
<input type="hidden" name="weight_unit" value="kgs">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="undefined_quantity" value="1">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="cn" value="Special Instructions">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="return" >
<input type="hidden" name="on0" value="Colour">
<!-- Combo Box combo_30 -->
<!--Preamble-->
<select name="os0" size="1" style="position:absolute; left:8px; top:8px; /*Tag Style*/" __AddCode="here">
<option value="Black" __AddCode="here">Black</option>
<option value="White" __AddCode="here">White</option>
</select>
<!--Postamble-->
<!-- Button btn_29 -->
<!--Preamble-->
<div style="position:absolute;left:75px;top:2px;width:116px;height:28px;"><button type="submit" id="btn_29" class="Button4" style="width:116px;height:28px;"><span>Buy Now</span></button></div>
<!--Postamble-->
</form>
<!--Postamble-->
<!--MainDivEnd-->
</div>
黑色
白色
立即购买
从以下位置添加到购物车:
<form id="form_36" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_self" style="margin:0;position:absolute;left:647px;top:957px;width:271px;height:44px; /*MainDivStyle*/" __AddCode="here">
<!--MainDivStart-->
<input type="hidden" name="bn" value="Serif.WebPlus">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="info@mysite.com">
<input type="hidden" name="item_name" value="Polo Shirt">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="amount" value="20.00">
<input type="hidden" name="weight" value="0.18">
<input type="hidden" name="weight_unit" value="kgs">
<input type="hidden" name="add" value="1">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="on0" value="Colour">
<!-- Combo Box combo_31 -->
<!--Preamble-->
<select name="os0" size="1" style="position:absolute; left:8px; top:8px; /*Tag Style*/" __AddCode="here">
<option value="Black" __AddCode="here">Black</option>
<option value="White" __AddCode="here">White</option>
</select>
<!--Postamble-->
<!-- Button btn_24 -->
<!--Preamble-->
<div style="position:absolute;left:75px;top:0px;width:188px;height:36px;"><button type="submit" id="btn_24" class="Button5" style="width:188px;height:36px;"><span>Add to Cart</span></button></div>
<!--Postamble-->
</form>
黑色
白色
添加到购物车
希望这张照片能让我更深入地了解我想做什么
正如我所看到的,两种表单中的字段是相似的,因此我建议只保留第一种表单,删除第二种表单,将两个按钮都放在第一种表单中,并使用
javascript
在命令之间切换:
第一种形式的变化:
添加另一个隐藏字段(购物车选项必需)
在两个按钮上单击事件添加
<button type="submit" id="btn_29" class="Button4" style="width:116px;height:28px;" onclick="setCMD('_xclick');"><span>Buy Now</span></button>
<button type="submit" id="btn_24" class="Button5" style="width:188px;height:36px;" onclick="setCMD('_cart');"><span>Add to Cart</span></
立即购买
谢谢你的帮助。现在发生的事情是,两个按钮(立即购买和添加到购物车)都将项目添加到购物车。因此,“添加到购物车”按钮起作用,但“立即购买”按钮不起作用。这对我来说很好。我还尝试复制您提供的链接中的代码,并添加了javascript函数,结果成功了!您正在使用哪个浏览器?
<button type="submit" id="btn_29" class="Button4" style="width:116px;height:28px;" onclick="setCMD('_xclick');"><span>Buy Now</span></button>
<button type="submit" id="btn_24" class="Button5" style="width:188px;height:36px;" onclick="setCMD('_cart');"><span>Add to Cart</span></
<script type="text/javascript">
function setCMD(cmd) {
form = document.getElementById("form_35");
form.cmd.value = cmd;
}
</script>