用XMLDOM实现购物车遇到的问题..
添加购物车:addbag.asp
<%
Dim productid,conn,rst,strconn,strSQl,avarProduct
productid=trim(request.querystring("productid"))
strconn=session("strconn")
set conn=server.createobject("adodb.connection")
conn.open strconn
set rst=server.createobject("adodb.recordset")
strSQL="select * from t_product where productid="&productid
rst.open strSQL,conn,1,1
set XMLDoc=server.createobject("Microsoft.XMLDOM")
if not isempty(session("bagitems")) then
XMLDoc.loadXML Cstr(session("bagitems"))
set bagitems=XMLDoc.documentElement
else
set BagItems=XMLDoc.createElement("bagitems")
set XMLDoc.documentElement=bagitems
end if
if not rst.eof then
set nodeFind=bagitems.selectNodes("product[@productid="&productid&"]")
if nodeFind.length=0 then
set product=XMLDoc.createElement("product")
set attr=XMLDoc.createAttribute("productid")
attr.text=rst("productid")
product.attributes.setNamedItem(attr)
set attr=XMLDoc.createAttribute("product_name")
attr.text=rst("product_name")
product.attributes.setNamedItem(attr)
set attr=XMLDoc.createAttribute("price")
attr.text=rst("price")
product.attributes.setNamedItem(attr)
set attr=XMLDoc.createAttribute("del")
attr.text="del"
product.attributes.setNamedItem(attr)
product.text="1"
bagitems.appendChild(product)
end if
end if
rst.close
conn.close
session("bagitems")=bagitems.XML
%>
显示购物车:showbag.asp
<html><head><title>显示购物车</title></head>
<body bgcolor=#ffffff>
<%
set XMLDoc=server.createobject("Microsoft.XMLDOM")
'if not isempty(session("bagitems")) then
if session("bagitems")<>"" then
XMLDoc.loadXML cstr(session("bagitems"))
set bagitems=XMLDoc.documentElement
else
set bagitems=XMLDoc.createElement("bagitems")
set XMLDoc.documentElement=bagitems
end if
'添加或修改产品
if Request.servervariables("content_length")>0 then
select case trim(request.form("do"))
case "继续购买"
response.redirect "index.asp"
response.end
case "更改数量"
RecalcBag bagitems
case "下订单"
response.redirect "save_shopcart.asp"
response.end
end select
end if
session("bagitems")=bagitems.XML
'if session("bagitems")="" then
'response.write "对不起,您还没有选购图书!!!"
'else
if bagitems.hasChildNodes then
printBag bagitems
else
response.write "对不起,您还没有选购图书!!!"
end if
'end if
%>
</body></html>
<script language=VBscript runat=server>
sub RecalcBag(bagitems)
for each item in bagitems.ChildNodes
nQty=trim(request.form("Qty"&item.attributes.getNamedItem("productid").text))
if nQty<>"" then
if nQty<1 then
bagitems.removeChild item
else
item.text=nQty
end if
end if
next
end sub
sub PrintBag(bagitems)
response.write "<form method=post action="
response.write request.servervariables("script_name")&">"
response.write "<table><tr><th>数量</th><th colspan=2>"
response.write "产品名</th><th>单价</th><th>价格</th>"
response.write "</tr>"&vbcrlf
for each item in bagitems.childNodes
response.write "<tr><td><input type=text name="
response.write "Qty"&item.attributes.getNamedItem("productid").text
response.write " value="&item.text&" size=3></td>"
response.write "<td colspan=2>"&item.attributes.getNamedItem("product_name").text&"</td>"
response.write "<td>"&FormatCurrency(item.attributes.getNamedItem("price").text)&"</td>"
subtotal=item.text*item.attributes.getNamedItem("price").text
total=total+subtotal
response.write "<td><b>"&formatCurrency(subtotal)&"</b><td>"
response.write "</tr>"&vbCrlF
next
response.write "<tr><td colspan=5><hr></td></tr>"
response.write "<tr><td colspan=3></td><td><b>总价:</b></td>"
response.write "<td><b>"&formatcurrency(total)&"</b></td></tr>"&vbcrlf
response.write "<tr><td colspan=5 align=right>"
response.write "<input type=submit name=do value=下订单> "
response.write "<input type=submit name=do value=更改数量> "
response.write "<input type=submit name=do value=继续购买>"
response.write "</td></tr></table></form>"
end sub
</script>
这种方法中要删除购物车中的产品,应该装数量修改为小于0时才能删除某个产品..
现在我要添加一个checkbox控件来删除购物车中的某个产品,如何实现,谢谢!