asp购物车代码

博学站 人气:1.88W

asp购物车代码怎么写?为帮助大家顺利写出ASP购物车的源代码,本文yjbys小编主要介绍了ASP购物车实现过程,需要的朋友可以参考下!

asp购物车代码

  代码如下

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

<script type="text/javascript" src="js/"></script>

<style type="text/css">

a{text-decoration:none;}

td,p{font-size:12px}

</style>

</head>

<body>

<%

dim action,bookid,aProducts,delid,i,conn,rs,sql,sNewProducts

set conn = teObject("ection")

ectionstring="provider=b.4.0;data source="&server.MapPath("#")

action=yString("action")

if yString("id")="" then

bookid=Session("productlist")'//////////////////////////////////调入查询物品的

else

if Session("productlist")="" then

Session("productlist")=yString("id")

bookid=yString("id")

else

if InStr(Session("productlist"),yString("id"))<1 then

bookid=Session("productlist")+","+yString("id")'//////////////把id全部存储到bookid中类似与数组

Session("productlist")=bookid

else

bookid=Session("productlist")

end if

end if

end if

if Session("productlist")="" then'////////////////////////若id为空,则说明用户没有购物

bookid=0

end if

if action="del" then '删除购物车中的某一件商品

aProducts=Split(Session("ProductList"),",")

delid=CStr(Trim(yString("id")))

For i=0 To UBound(aProducts) '循环所有商品ID

If trim(aProducts(i))<>delid then

'不等于被删除的ID时则保存进新的列表

sNewProducts = sNewProducts & "," & aProducts(i)

end if

Next

Session("ProductList") = mid(sNewProducts,2)

if Session("ProductList")="" then

bookid=0

else

bookid=Session("ProductList")

end if

elseif action="delall" then

Session("ProductList")=""

rect("")

end if

%>

<form name="myform" method="post" action="">

<input type="hidden" name="id" value="<%= bookid %>" />

<table width="90%" border="1" cellspacing="5" cellpadding="3" style="border-collapse:collapse; margin-bottom:20px;">

<tr>

<td align="center">商品id</td>

<td align="center">商品名称</td>

<td align="center">商品单价</td>

<td align="center">订购数量</td>

<td align="center">商品金额</td>

<td align="center">操作</td>

</tr>

<%

'根据临时存储到Session里的商品ID分别从商品数据库循环调出商品显示到购物车页面,遇到重复ID不显示

Dim Quatity,sum,aa '判断input 名

sum=0

if bookid<>0 and bookid<>"" then

set rs=teObject("rdset")

sql="select id,product_name,price,info from product where id in ("&bookid&") order by id" '这里替换成实际的商品数据库及字段

sql,conn,1,1

if not ( and ) then

aa=1

Do While Not

Quatity = CInt(Request("sl"&aa))

If Quatity <=0 Then Quatity = 1 '以下为购物车每一件商品内容,包含ID、名称、数量及取消

%>

<tr>

<td align="center"><%=rs("id")%></td>

<td align="center"><a href="("id")%>" title="<%=rs("info")%>" target="_blank"><%=rs("product_name")%></a></td>

<td align="center"><span id="unitprice<%= aa %>"><%=rs("price")%></span></td>

<td align="center">

<input type="hidden" id="itemId<%= aa %>" value="<%= rs("id") %>" />

<input type="button" value="-" onclick="myfun(1,'<%= aa %>')" />

<input name="sl<%=aa%>" id="sl<%= aa %>" type="text" value="<%= Quatity %>" size="3" readonly="readonly" />

<input type="button" value="+" onclick="myfun(2,'<%= aa %>')" /></td>

<td align="center"><span id="total<%= aa %>"><%=(rs("price")*Quatity)%></span></td>

<td align="center"><a href="?id=<%=rs("id")%>&action=del"><font color="#FF0000" size="4" style="font-weight:bold">×</font></a></td>

</tr>

<%'循环读取ASP购物车内的商品

sum=FormatNumber(rs("price")*Quatity+sum,2)

next

aa=aa+1

Loop

else

e("<tr><td align='center' colspan='6'>暂无选购的商品,请继续<a href=''>购物</a></td></tr>")

end if

e

set rs=nothing

Else

e("<tr><td align='center' colspan='6'>暂无选购的商品,请继续<a href=''>购物</a></td></tr>")

end if

e

set conn=nothing

%>

</table>

</form>

<p style="text-align:right; width:90%">

<input type="button" value="清空购物车" onclick="if(confirm('确定要清空购物车么?')){='?action=delall';}" />

总价:<span id="tcount"><%= sum %></span>元

<input type="button" value="继续购物" onclick="='';" />

<input type="button" value="立即结算" onclick="nextStep();" />

</p>

<script type="text/javascript">

function round(v,e){

var t=1;

for(;e>0;t*=10,e--);

for(;e<0;t/=10,e++);

return d(v*t)/t;

}

function myfun(str,obj){

var quantity,sum=0;

if(str==1){

if(lementById("sl"+obj)e>1){

lementById("sl"+obj)e--;

}

}

else{

lementById("sl"+obj)e++;

}

quantity=$("#sl"+obj)();

$("#total"+obj)(round($("#unitprice"+obj)()*quantity,2));

for(var i=1;i<<%= aa %>;i++){

sum+=round($("#total"+i)(),2);

}

sum=round(sum,2);

$("#tcount")(sum);

var strTemp;

for(var j=1;j<<%= aa %>;j++){

if(j==1){

strTemp=$("#itemId"+j)()+"|"+$("#sl"+j)()+"|"+$("#total"+j)();

}

else{

strTemp+="#"+$("#itemId"+j)()+"|"+$("#sl"+j)()+"|"+$("#total"+j)();

}

}

//alert(strTemp);

}

function nextStep(){

var strTemp;

for(var j=1;j<<%= aa %>;j++){

if(j==1){

strTemp=$("#itemId"+j)()+"|"+$("#sl"+j)()+"|"+$("#total"+j)();

}

else{

strTemp+="#"+$("#itemId"+j)()+"|"+$("#sl"+j)()+"|"+$("#total"+j)();

}

}

$("",{str:strTemp,rnd:new Date()ime()},function(msg){alert(msg);})

}

</script>

</body>

</html>

   如下代码:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<%

dim conn,str,i,strArr,arrstr

set conn = teObject("ection")

ectionstring="provider=b.4.0;data source="&server.MapPath("#")

str=("str")

strArr=split(str,"#")

for i=0 to ubound(strArr)

arrstr=split(strArr(i),"|")

ute("insert into [orders](productId,Quantity,total) values("&arrstr(0)&","&arrstr(1)&","&arrstr(2)&")")

next

e("success")

e

set conn=nothing

%>