0

我的购物车已准备就绪并且可以正常工作,但现在我需要在我的数据库中的产品 ID 和客户尺寸选择之间进行重新关联。有人可以帮我吗?请参阅下面我的 html 中的代码更改为 php:

<form method="POST" autocomplete="off" title="Product">
  <input name="title" type="hidden" id="title" value="Product"">
    <label>Size</label>
    <label><input type="radio" name="Size1" value="22" id="22"> M </label>
    <label><input type="radio" name="size2" value="23" id="23"> L </label>
<div>
<a id="shoppingcart" href="cart2.php?add=.(I would like to place the id 22 or 23 here`enter code here`)" target="_self"><img src="images/carrinho01.jpg" alt="noiva em detalhes" width="100%" height="100%" align="rigth" margin-right="8%"/></a>
4

1 回答 1

1

您所追求的是一些 JavaScript 在选择大小时更改 URL。我根据您的代码在下面制作了一个非常简单的示例。

显着变化:

  • 无线电的name值需要相同,以便它们属于同一组。
  • 添加onclick到调用setShoppingCartUrl函数的无线电输入
  • 将单选的值添加到 URL 并设置链接的 JavaScript

例子:

baseurl = 'cart2.php?add=';

function setShoppingCartUrl(e) {
    document.getElementById('shoppingcart').href=baseurl+e.value
}
<form method="POST" autocomplete="off" title="Product">
  <input name="title" type="hidden" id="title" value="Product"">
    <label>Size</label>
    <label><input type="radio" name="size" value="22" id="22" onclick ="setShoppingCartUrl(this)"> M </label>
    <label><input type="radio" name="size" value="23" id="23" onclick ="setShoppingCartUrl(this)"> L </label>
<div>
<a id="shoppingcart" href="#" target="_self"><img src="images/carrinho01.jpg" alt="noiva em detalhes" width="100%" height="100%" align="rigth" margin-right="8%"/></a>

于 2015-08-30T03:42:38.340 回答