【发布时间】:2011-12-30 07:44:56
【问题描述】:
我有一个这样的访问表:有 100 个产品
Product Id,
Product Name,
Image Path,
Price
我可以使用 ASP 代码轻松地在我的网页上显示这些产品。
我想在每个产品下添加一个按钮,允许用户将产品添加到购物车。
我的页面一次显示 30 个项目。这是我的页面的 HTML。当我点击任何按钮时,我会调用下面提到的 java stipt 函数来提交表单。
<table class="retail">
<tr>
<td>
<img src="images/<%=rs.fields("image")%>" width="125" height="125"/>
<td>
</tr>
<tr><td> </td></tr>
<tr>
<td style="font-weight: bold;color: #151B8D;text-align: center;font-size: 10px; padding: 5px 5px 5px 5px;">
<%=rs.fields("details")%>
<td>
</tr>
<tr><td> </td></tr>
<tr>
<td style="font-weight: bold;color: red;text-align: center;font-size: 14px; padding: 0px 1px 1px 1px;">
<%=rs.fields("productid")%>
<td>
</tr>
<tr><td> </td></tr>
<tr>
<td style="font-weight: bold;color: red;text-align: center;font-size: 16px; padding: 0px 1px 1px 1px;">
USD $<%=rs.fields("price")%>.00
</td>
<input type="hidden" id="details" name="details"/>
<input type="hidden" id="productid" name="productid"/>
<input type="hidden" id="price" name="price"/>
</tr>
<tr>
<td>
<input type="button" value="Add to Trolly" id="cmdAdd" name="cmdAdd" onClick="javascript:callMe(this,'<%=rs.fields("details")%>','<%=rs.fields("productid")%>','<%=rs.fields("price")%>')"/>
</td>
</tr>
</table>
<SCRIPT LANGUAGE="JavaScript">
function callMe(obj,details,prod_id,price) {
var prodnm = document.getElementById("productid");
prodnm.value = prod_id;
var itemprice = document.getElementById("price");
itemprice.value = price;
var trollyform = document.getElementById("trollyform");
document.forms["trollyform"].submit();
}
这是我为检查表单提交值而编写的代码:
<%
Response.Write "<br>Product Code value : " & request.Form("productid")
Response.Write "<br>Price value : " & request.Form("price")
%>
作为回应,我得到了这个:
我的页面显示 30 件商品,如果我单击任何添加到购物车按钮,它就会给我这个。所以我点击的按钮,它给了我价值,但它也给了我逗号分隔的休息值
产品代码值:RNG-2, , , , , , , , , , , , , , , , , , , , , , , , , , , , , 价格价值: 10, , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
基本上第一个值是我为该页面上的其余产品单击的产品按钮的值,它给了我逗号
【问题讨论】:
-
您使用产品 ID。它绝对是主键,并且会唯一标识每一个产品,对吧?
-
如果
Product id不是主键,则通常创建一个随机 ID,或者您可以使用自动增量值,这需要您在表中创建一个新字段。 -
附注:您是否考虑过在每篇文章旁边放置一个复选框和一个“全局”添加到购物车按钮?
-
问题是您使用多个值填充表单输入“productid”。您发布的代码是整页代码吗?如果不发布所有内容。
标签: asp-classic