请教一个购物成问题,ASP为基础的购物车,用JS如何更新数据(数量部分)
注:以下购物车代码为目前常用的形式,我想改写成,由购物页面直接填写购物数量,提交到购物车中,并且在购物车中能更新各个商品的数量。
附上参考代码,图片
请教一个购物成问题,ASP为基础的购物车,用JS如何更新数据(数量部分)
注:以下购物车代码为目前常用的形式,我想改写成,由购物页面直接填写购物数量,提交到购物车中,并且在购物车中能更新各个商品的数量。
********************************************************************************************************
附上参考代码,图片
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>广州办公易文化用品批发配送网</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<script language="Javascript">
var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
//extra height in px to add to iframe in FireFox 1.0+ browsers
var FFextraHeight=getFFVersion>=0.1? 16 : 0
function dyniframesize(iframename) {
var pTar = null;
if (document.getElementById){
pTar = document.getElementById(iframename);
}
else{
eval('pTar = ' + iframename + ';');
}
if (pTar && !window.opera){
//begin resizing iframe
pTar.style.display="block"
if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight){
//ns6 syntax
pTar.height = pTar.contentDocument.body.offsetHeight+FFextraHeight;
}
else if (pTar.Document && pTar.Document.body.scrollHeight){
//ie5+ syntax
pTar.height = pTar.Document.body.scrollHeight;
}
}
}
</script>
</head>
<body>
<%
Sub PutToShopBag( Prodid, ProductList )
If Len(ProductList) = 0 Then
ProductList =Prodid
ElseIf InStr( ProductList, Prodid ) <= 0 Then
ProductList = ProductList&", "&Prodid &""
End If
End Sub
ProductList = Session("ProductList")
Products = Split(Request("Prodid"), ",")
For I=0 To UBound(Products)
PutToShopBag Products(I), ProductList
Next
Session("ProductList") = ProductList
'************************************************************************************
Sub PutToShopBagProperty1( selectProperty1, selectProperty1List )
tmpStr = Split( selectProperty1,"|")
tmpStrID = tmpStr(0)
tmpStrName = tmpStr(1)
'Response.write "Session:"&Session("selectProperty1List")&"<br>"
'Response.write "tmpStrID:"&tmpStrID&"<br>"
'Response.write "tmpStrName:"&tmpStrName&"<br>"
If Len(selectProperty1List) = 0 Then
selectProperty1List =selectProperty1
Else
'Response.write "selectProperty1List:"&selectProperty1List&"<br>"
tmpList = Split( selectProperty1List,",")
'Response.write "UBound(tmpList):"&UBound(tmpList)&"<br>"
For i=0 To UBound(tmpList)
tmp = Split(tmpList(i),"|")
'response.write tmp(0)&"<br>"
if Trim(tmp(0)) <> "" then
if Trim(tmp(0)) = Trim(tmpStrID) then
'表示找到了,则改变为最新的选择情况
Flag = "True"
'Response.write tmp(0)&"|"&tmp(1) &"<br>"
'Response.write selectProperty1 & "<br>"
selectProperty1List = replace(selectProperty1List,tmp(0)&"|"&tmp(1),selectProperty1)
'Response.Write selectProperty1List & "<br>"
Exit For
end if
end if
Next
'没有的话,则直接加一个到Session里面
if Flag <> "True" then selectProperty1List = selectProperty1List&", "&selectProperty1 &""
End If
End Sub
selectProperty1List = Session("selectProperty1List")
Products = Split(Request("selectProperty1"), ",")
For I=0 To UBound(Products)
PutToShopBagProperty1 Products(I), selectProperty1List
Next
Session("selectProperty1List") = selectProperty1List
Sub PutToShopBagProperty2( selectProperty2, selectProperty2List )
tmpStr = Split( selectProperty2,"|")
tmpStrID = tmpStr(0)
tmpStrName = tmpStr(1)
'Response.write "Session:"&Session("selectProperty2List")&"<br>"
'Response.write "tmpStrID:"&tmpStrID&"<br>"
'Response.write "tmpStrName:"&tmpStrName&"<br>"
If Len(selectProperty2List) = 0 Then
selectProperty2List =selectProperty2
Else
'Response.write "selectProperty2List:"&selectProperty2List&"<br>"
tmpList = Split( selectProperty2List,",")
'Response.write "UBound(tmpList):"&UBound(tmpList)&"<br>"
For i=0 To UBound(tmpList)
tmp = Split(tmpList(i),"|")
'response.write tmp(0)&"<br>"
if Trim(tmp(0)) <> "" then
if Trim(tmp(0)) = Trim(tmpStrID) then
'表示找到了,则改变为最新的选择情况
Flag = "True"
'Response.write tmp(0)&"|"&tmp(2) &"<br>"
'Response.write selectProperty2 & "<br>"
selectProperty2List = replace(selectProperty2List,tmp(0)&"|"&tmp(1),selectProperty2)
'Response.Write selectProperty2List & "<br>"
Exit For
end if
end if
Next
'没有的话,则直接加一个到Session里面
if Flag <> "True" then selectProperty2List = selectProperty2List&", "&selectProperty2 &""
End If
End Sub
selectProperty2List = Session("selectProperty2List")
Products = Split(Request("selectProperty2"), ",")
For I=0 To UBound(Products)
PutToShopBagProperty2 Products(I), selectProperty2List
Next
Session("selectProperty2List") = selectProperty2List
Sub PutToShopBagProperty3( selectProperty3, selectProperty3List )
tmpStr = Split( selectProperty3,"|")
tmpStrID = tmpStr(0)
tmpStrName = tmpStr(1)
'Response.write "Session:"&Session("selectProperty3List")&"<br>"
'Response.write "tmpStrID:"&tmpStrID&"<br>"
'Response.write "tmpStrName:"&tmpStrName&"<br>"
If Len(selectProperty3List) = 0 Then
selectProperty3List =selectProperty3
Else
'Response.write "selectProperty3List:"&selectProperty3List&"<br>"
tmpList = Split( selectProperty3List,",")
'Response.write "UBound(tmpList):"&UBound(tmpList)&"<br>"
For i=0 To UBound(tmpList)
tmp = Split(tmpList(i),"|")
'response.write tmp(0)&"<br>"
if Trim(tmp(0)) <> "" then
if Trim(tmp(0)) = Trim(tmpStrID) then
'表示找到了,则改变为最新的选择情况
Flag = "True"
'Response.write tmp(0)&"|"&tmp(3) &"<br>"
'Response.write selectProperty3 & "<br>"
selectProperty3List = replace(selectProperty3List,tmp(0)&"|"&tmp(1),selectProperty3)
'Response.Write selectProperty3List & "<br>"
Exit For
end if
end if
Next
'没有的话,则直接加一个到Session里面
if Flag <> "True" then selectProperty3List = selectProperty3List&", "&selectProperty3 &""
End If
End Sub
selectProperty3List = Session("selectProperty3List")
Products = Split(Request("selectProperty3"), ",")
For I=0 To UBound(Products)
PutToShopBagProperty3 Products(I), selectProperty3List
Next
Session("selectProperty3List") = selectProperty3List
Sub PutToShopBagProperty4( selectProperty4, selectProperty4List )
tmpStr = Split( selectProperty4,"|")
tmpStrID = tmpStr(0)
tmpStrName = tmpStr(1)
'Response.write "Session:"&Session("selectProperty4List")&"<br>"
'Response.write "tmpStrID:"&tmpStrID&"<br>"
'Response.write "tmpStrName:"&tmpStrName&"<br>"
If Len(selectProperty4List) = 0 Then
selectProperty4List =selectProperty4
Else
'Response.write "selectProperty4List:"&selectProperty4List&"<br>"
tmpList = Split( selectProperty4List,",")
'Response.write "UBound(tmpList):"&UBound(tmpList)&"<br>"
For i=0 To UBound(tmpList)
tmp = Split(tmpList(i),"|")
'response.write tmp(0)&"<br>"
if Trim(tmp(0)) <> "" then
if Trim(tmp(0)) = Trim(tmpStrID) then
'表示找到了,则改变为最新的选择情况
Flag = "True"
'Response.write tmp(0)&"|"&tmp(4) &"<br>"
'Response.write selectProperty4 & "<br>"
selectProperty4List = replace(selectProperty4List,tmp(0)&"|"&tmp(1),selectProperty4)
'Response.Write selectProperty4List & "<br>"
Exit For
end if
end if
Next
'没有的话,则直接加一个到Session里面
if Flag <> "True" then selectProperty4List = selectProperty4List&", "&selectProperty4 &""
End If
End Sub
selectProperty4List = Session("selectProperty4List")
Products = Split(Request("selectProperty4"), ",")
For I=0 To UBound(Products)
PutToShopBagProperty4 Products(I), selectProperty4List
Next
Session("selectProperty4List") = selectProperty4List
Sub PutToShopBagProperty5( selectProperty5, selectProperty5List )
tmpStr = Split( selectProperty5,"|")
tmpStrID = tmpStr(0)
tmpStrName = tmpStr(1)
'Response.write "Session:"&Session("selectProperty5List")&"<br>"
'Response.write "tmpStrID:"&tmpStrID&"<br>"
'Response.write "tmpStrName:"&tmpStrName&"<br>"
If Len(selectProperty5List) = 0 Then
selectProperty5List =selectProperty5
Else
'Response.write "selectProperty5List:"&selectProperty5List&"<br>"
tmpList = Split( selectProperty5List,",")
'Response.write "UBound(tmpList):"&UBound(tmpList)&"<br>"
For i=0 To UBound(tmpList)
tmp = Split(tmpList(i),"|")
'response.write tmp(0)&"<br>"
if Trim(tmp(0)) <> "" then
if Trim(tmp(0)) = Trim(tmpStrID) then
'表示找到了,则改变为最新的选择情况
Flag = "True"
'Response.write tmp(0)&"|"&tmp(5) &"<br>"
'Response.write selectProperty5 & "<br>"
selectProperty5List = replace(selectProperty5List,tmp(0)&"|"&tmp(1),selectProperty5)
'Response.Write selectProperty5List & "<br>"
Exit For
end if
end if
Next
'没有的话,则直接加一个到Session里面
if Flag <> "True" then selectProperty5List = selectProperty5List&", "&selectProperty5 &""
End If
End Sub
selectProperty5List = Session("selectProperty5List")
Products = Split(Request("selectProperty5"), ",")
For I=0 To UBound(Products)
PutToShopBagProperty5 Products(I), selectProperty5List
Next
Session("selectProperty5List") = selectProperty5List
'****************品牌属性开始搜索**********************************
Sub PutToShopBagProperty6( selectProperty6, selectProperty6List )
tmpStr = Split( selectProperty6,"|")
tmpStrID = tmpStr(0)
tmpStrName = tmpStr(1)
'Response.write "Session:"&Session("selectProperty1List")&"<br>"
'Response.write "tmpStrID:"&tmpStrID&"<br>"
'Response.write "tmpStrName:"&tmpStrName&"<br>"
If Len(selectProperty6List) = 0 Then
selectProperty6List =selectProperty6
Else
'Response.write "selectProperty1List:"&selectProperty1List&"<br>"
tmpList = Split( selectProperty6List,",")
'Response.write "UBound(tmpList):"&UBound(tmpList)&"<br>"
For i=0 To UBound(tmpList)
tmp = Split(tmpList(i),"|")
'response.write tmp(0)&"<br>"
if Trim(tmp(0)) <> "" then
if Trim(tmp(0)) = Trim(tmpStrID) then
'表示找到了,则改变为最新的选择情况
Flag = "True"
'Response.write tmp(0)&"|"&tmp(1) &"<br>"
'Response.write selectProperty1 & "<br>"
selectProperty6List = replace(selectProperty6List,tmp(0)&"|"&tmp(1),selectProperty6)
'Response.Write selectProperty1List & "<br>"
Exit For
end if
end if
Next
'没有的话,则直接加一个到Session里面
if Flag <> "True" then selectProperty6List = selectProperty6List&", "&selectProperty6 &""
End If
End Sub
selectProperty6List = Session("selectProperty6List")
Products = Split(Request("selectProperty6"), ",")
For I=0 To UBound(Products)
PutToShopBagProperty6 Products(I), selectProperty6List
Next
Session("selectProperty6List") = selectProperty6List
'************************** 搜索结束 ************************************************
if request("payment")="去收银台" then
response.redirect "b2b_ddlcsys.asp?action=1"
end if
If Request("cmdShow") = "Yes" Then
ProductList = ""
Products = Split(Request("ProdId"), ", ")
For I=0 To UBound(Products)
PutToShopBag Products(I), ProductList
Next
Session("ProductList") = ProductList
End If
If Len(Session("ProductList")) = 0 Then
Response.write "<br><table width='350' border='0' align='center' cellpadding='0' cellspacing='3' bgcolor='#F0F0F0'><tr><td height='150' valign='top' bgcolor='#FFFFFF'><br><table width='95%' border='0' align='center' cellpadding='0' cellspacing='3'><tr><td height='30' align='center' class='cn20'><b>广州办公易文化用品批发配送网提示您!</b></td></tr><tr><td height='3' bgcolor='#66CC33'></td></tr><tr><td height='30' align='center' class='en12-big'><b>你的购物车当前为空!</b></td></tr><tr><td height='30' align='center' class='en12-black'><a href=products.asp>去商城逛逛</a> <a href=""JavaScript:onClick=window.close();"">关闭窗口</a></td></tr></table></td></tr></table>"
Response.end
end if
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><!--#include file="head.asp"--></td>
</tr>
</table><!--#include file="b2b_sys.asp"-->
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="798" height="176">
<param name="movie" value="flash/top.swf">
<param name="quality" value="high">
<embed src="flash/top.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="798" height="176"></embed>
</object></td>
<td width="798" align="center"><img src="images/order-line.jpg" width="197" height="175"></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="204" height="5"><img src="images/search_line.jpg"></td>
<td height="5" bgcolor="#8AE32F"><img name="" src="" width="1" height="5" alt=""></td>
</tr>
</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="204" align="center" valign="top"><!--#include file="search.asp"-->
<table width="200" border="0" align="center" cellpadding="0" cellspacing="2">
<tr>
<td><table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td width="3" bgcolor="#63BD28"> </td>
<td bgcolor="#FFFFFF" class="en12-big">常购物清单</td>
<td width="80" bgcolor="#ECECEC"> </td>
</tr>
</table></td>
</tr>
<tr>
<td><% if LngUserID="0" then %><table width="99%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ECECEC">
<tr>
<td height="30" align="center" bgcolor="#FFFFFF" class="en12-blue"><img src="images/car.jpg" width="17" height="16" align="absmiddle"> 非注册用户,没有统计信息.</td>
</tr>
</table> <% else
set rssh=server.CreateObject("adodb.recordset")
rssh.open "select top 10 id ,sum(productnum) as num from orders where username='"&strUserName&"' group by id ",conn,1,1
if rssh.eof and rssh.bof then
response.write ("<table width='99%' border='0' cellspacing='0' cellpadding='0'><tr><td class='en12-black'><a href='products.asp'>目前您尚未在本站购买商品!去商城逛逛。</a></td></tr></table>")%>
<% else
hy=1
bcolor="#ffffff"
do while not rssh.eof %><table width="95%" border="0" align="center" cellpadding="0" cellspacing="1" class="en12-black">
<tr>
<td height="18" align="left" bgcolor=<%=bcolor%>>
<% set rss=server.CreateObject("adodb.recordset")
rss.open "select name,id from product where id="&rssh("id")&"",conn,1,1
response.write(" <li><a href='product.asp?id="&rss("id")&"'> "&rss("name")&" </a></li>")
rss.close%>
[<%= rssh("num")%>] </td>
</tr>
</table><% hy=hy+1
if hy mod 2=0 then
bcolor="#f7f7f7"
end if
rssh.movenext
loop
rssh.close
end if%><% end if%></td>
</tr>
</table></td>
<td width="785" align="left" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/mycar.jpg" width="780" height="41"></td>
</tr>
<tr>
<td><img src="images/welcometocar.jpg" width="777" height="77"></td>
</tr>
<tr>
<td><table border="0" cellspacing="1" cellpadding="4" align="center" width="100%" bgcolor="#f2f2f2" class="en12-black">
<form action="shopcar.asp" method="POST" name="check" ><tr bgcolor="#f7f7f7" height="25" align="center">
<td width="10%" bgcolor="#f7f7f7"><strong>编 号</strong></td>
<td><strong>商 品 名 称</strong></td>
<td><strong> 单 位</strong></td>
<td><strong>数 量</strong></td>
<td><strong>单 价</strong></td>
<td><strong>积 分</strong></td>
<td><strong>小 计</strong></td>
</tr>
<%
Set rsCheck=Server.CreateObject("ADODB.RecordSet")
strsql="select ID,Name,Score,pweight,type,Price1,Price2," & LstPrice & ",amount,VipPrice,Pic,Code from Product where ID in ("&Session("ProductList")&") order by ID"
rsCheck.open strsql,conn,1,1
Sum = 0
SumS = 0
Quatity = 1
NUMS=1
Do While Not rsCheck.EOF
Quatity = CInt( Request.Form( "Q_" & rsCheck("ID")) )
If Quatity <= 0 Then
Quatity = CInt( Session(rsCheck("ID")) )
If Quatity <= 0 Then Quatity = 1
End If
Session(rsCheck("ID")) = Quatity
Dim YourPrice,strprice2,strvipprice,ProScore
strprice1 = Round(rsCheck("Price1"),2)
strprice2 = Round(rsCheck("Price2"),2)
strvipprice = Round(rsCheck("VipPrice"),2)
ProScore = rsCheck("Score")
YourPrice = Round(rsCheck("" & LstPrice & ""),2)
Sum = Sum + (YourPrice + strvipprice)*Quatity
Sum=Round(Sum,2)
SumS = SumS + ProScore*Quatity
%>
<tr bgcolor="#FFFFFF" height="25" align="center">
<td><input type="CheckBox" name="ProdId" value="<%=rsCheck("ID")%>" Checked>
[<%=NUMS%>]</td>
<td align="left">
<a href="product.asp?ID=<%=rsCheck("ID")%>" target="_blank"><%=rsCheck("Name")%></a><a href="product.asp?ID=<%=rsCheck("ID")%>" target="_blank"> </a> </td>
<td><%=rsCheck("TYPE") %></td>
<td><input type="Text" name="<%="Q_" & rsCheck("ID")%>" value="<%=Quatity%>" size="6" class="input_sr" onMouseOver="this.focus()" onMouseOut="if(this.value=='')this.value='';" onFocus="this.select()" onClick="if(this.value=='')this.value=''" ></td>
<td> <% if YourPrice <1 then response.write"0" end if%><%=YourPrice %></td>
<td> <%=ProScore %></td>
<td><%if Round((YourPrice + strvipprice)*Quatity,2)<1 then response.write"0" end if%><%=Round((YourPrice + strvipprice)*Quatity,2) %></td>
</tr>
<%NUMS=NUMS+1
rsCheck.MoveNext
Loop
rsCheck.close
set rsCheck=nothing
%>
<tr bgcolor="#F7F7F7">
<td height="25" colspan="8" align="center" valign="middle"><input name="order" type="submit" class="input_bot" value="更改商品">
<input name="payment" type="submit" class="input_bot" value="去收银台">
<input name="button" type="button" class="input_bot" onClick="javascript:window.close()" value="继续购物" language=javascript>
<input type="hidden" name="cmdShow" value="Yes">
您现在是:<%= strTitle %> | 价格总计:<font color="#FF0000"><b><%=Round(Sum,2) %></b></font> 元 | 获得积分:<%=SumS %> 分 </td>
</tr></form >
</table></td>
</tr>
</table>
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><!--#include file="foot.asp"--></td>
</tr>
</table>
</body>
</html>
[此贴子已经被作者于2007-7-13 15:26:03编辑过]